Skip to content

Conversation

otomad
Copy link
Contributor

@otomad otomad commented Mar 22, 2025

Which issue, if any, is this issue related to?

Closes #8436

Is there anything in the PR that needs further explanation?

Due to a special case font: math math; (the first math is the font-size, the second math is the font-family), it is not feasible to return the math directly in findFontFamily.

Currently this is done by checking in findFontFamily when the value is a keyword for both font-family and font-size, if its next node is a comma or it is already the last node, then treat it as a font-family keyword, otherwise treat it as a font-size keyword.

It seems that when using css-tree, it will not pass the invalid examples in the findFontFamily test, such as: 12pt/10pt Red/Black, 12pt/10pt Hawaii 5-0.

Copy link

changeset-bot bot commented Mar 22, 2025

🦋 Changeset detected

Latest commit: 723b391

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
stylelint Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@romainmenke
Copy link
Member

romainmenke commented Mar 23, 2025

Note:

As it seems that there is a plan to use the ESLint's CSSTree fork (#8465), so I have not tried to use CSSTree to implement this purpose.

That is entirely unrelated :)
You can use the current css-tree dependency.
Using the fork doesn't unlock any new capabilities.


@otomad, thank you for working on this issue.

Can you split this into two separate pull requests?
One for each rule/issue.

@otomad
Copy link
Contributor Author

otomad commented Mar 23, 2025

That is entirely unrelated :)
You can use the current css-tree dependency.
Using the fork doesn't unlock any new capabilities.

No, current css-tree doesn't support math value for font-size, so font: math math; will be invalid in current css-tree.

image

And if font-size: math; is added to mdn data (mdn/data#945), there is no need to fix declaration-property-value-no-unknown rule.

@romainmenke
Copy link
Member

romainmenke commented Mar 23, 2025

I meant that the current css-tree dependency already has all the needed capabilities.
We can add a custom syntax for this specific rule and use case. css-tree is extensible, we don't need to fork it to test for specific syntax that isn't part of the included data set.

Edit: my comment was purely intended to say that the existence of the fork and whether we switch to it or not should not be a factor in how we solve this specific issue. Either we can fix this issue with css-tree or we can not. I still think it is worthwhile to investigate what css-tree can do here as I think it might simplify and improve correctness of the parser for the font shorthand.


declaration-property-value-no-unknown is unrelated to font-family-no-missing-generic-family-keyword, correct?

@otomad
Copy link
Contributor Author

otomad commented Mar 24, 2025

Should I open a new issue before pull request?

Fix declaration-property-value-no-unknown false positives for math of font-size

@romainmenke
Copy link
Member

Our convention indeed is to first open an issue and then a pull request :)
Thank you

Copy link
Contributor

github-actions bot commented Mar 25, 2025

PR packaged and instant preview available.

View demo website

Install locally:

npm i -D https://pkg.pr.new/stylelint@723b391

(View Commit)

`12px serif, math font` is a invalid font value, but before current commit, this case will display a strange font name ("serif font") in the error.
@otomad
Copy link
Contributor Author

otomad commented Mar 25, 2025

Oops, it seems that break font-family-name-quotes.

image

It seems that it is useful to specify whether the property is font or font-family in the findFontFamily function.

Maybe 40cb5e5 have fixed it.
It's fixed.

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otomad Thank you for the pull request, and for splitting it into two.

Unless there are any objections, I think we can merge this as it fixes the issue. We can create an issue to investigate whether refactoring to use CSSTree can improve things. Someone can then pick that up if they have time.

Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing the math keyword for the font properties. Sounds great 👍🏼

I've left a few minor suggestions, so could you take a look? 🙏🏼

otomad added 2 commits April 2, 2025 02:05
Due to the possibility of `refactoring no-duplicate-at-import-rules`, `declaration-block-no-redundant-longhand-properties`, `color-function-notation`, etc. later to reuse `isCommaDiv` function, its type declaration is revised to make it more accurate.
Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏼

@jeddy3 jeddy3 merged commit 25ace65 into stylelint:main Apr 2, 2025
19 checks passed
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Apr 9, 2025
| datasource | package   | from    | to      |
| ---------- | --------- | ------- | ------- |
| npm        | stylelint | 16.17.0 | 16.18.0 |


## [v16.18.0](https://github.com/stylelint/stylelint/blob/HEAD/CHANGELOG.md#16180---2025-04-06)

It adds 2 new rules and fixes 2 bugs. We've turned on these rules, and the `syntax-string-no-invalid` and `layer-name-pattern` ones from recent releases, in our [standard config](https://www.npmjs.com/package/stylelint-config-standard).

-   Added: `color-function-alias-notation` rule ([#8499](stylelint/stylelint#8499)) ([@EduardAkhmetshin](https://github.com/EduardAkhmetshin)).
-   Added: `container-name-pattern` rule ([#8498](stylelint/stylelint#8498)) ([@nate10j](https://github.com/nate10j)).
-   Fixed: `declaration-property-value-no-unknown` false positives for `math` of `font-size` ([#8495](stylelint/stylelint#8495)) ([@otomad](https://github.com/otomad)).
-   Fixed: `font-family-no-missing-generic-family-keyword` false positives for `math` ([#8489](stylelint/stylelint#8489)) ([@otomad](https://github.com/otomad)).
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Apr 9, 2025
| datasource | package   | from    | to      |
| ---------- | --------- | ------- | ------- |
| npm        | stylelint | 16.17.0 | 16.18.0 |


## [v16.18.0](https://github.com/stylelint/stylelint/blob/HEAD/CHANGELOG.md#16180---2025-04-06)

It adds 2 new rules and fixes 2 bugs. We've turned on these rules, and the `syntax-string-no-invalid` and `layer-name-pattern` ones from recent releases, in our [standard config](https://www.npmjs.com/package/stylelint-config-standard).

-   Added: `color-function-alias-notation` rule ([#8499](stylelint/stylelint#8499)) ([@EduardAkhmetshin](https://github.com/EduardAkhmetshin)).
-   Added: `container-name-pattern` rule ([#8498](stylelint/stylelint#8498)) ([@nate10j](https://github.com/nate10j)).
-   Fixed: `declaration-property-value-no-unknown` false positives for `math` of `font-size` ([#8495](stylelint/stylelint#8495)) ([@otomad](https://github.com/otomad)).
-   Fixed: `font-family-no-missing-generic-family-keyword` false positives for `math` ([#8489](stylelint/stylelint#8489)) ([@otomad](https://github.com/otomad)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Fix font-family-no-missing-generic-family-keyword false positives for math
5 participants