Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bold and normal keyword aliases in scale/font-weights #73

Open
C0ZEN opened this issue Mar 7, 2022 · 3 comments
Open
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@C0ZEN
Copy link

C0ZEN commented Mar 7, 2022

What is the problem you're trying to solve?

The font-weights rules only cover numbers, and I prefer to use aliases when possible, but not EVERY alias.
This is not helping https://github.com/signal-noise/stylelint-scales/blob/master/lib/rules/font-weights/README.md.
And https://stylelint.io/user-guide/rules/list/font-weight-notation/ is not helping either.

What solution would you like to see?

Improve the https://github.com/signal-noise/stylelint-scales/blob/master/lib/rules/font-weights/README.md to also allow some aliases.

@jeddy3 jeddy3 changed the title White-list font-weights aliases Add support for bold and normal keyword aliases in scale/font-weights Mar 7, 2022
@jeddy3
Copy link
Owner

jeddy3 commented Mar 7, 2022

Thanks for the request and for using the template.

The rule intentionally only supports numerics font weights because they play well with variable fonts and we can do a naive find of the font-weight within the font shorthand:

https://github.com/signal-noise/stylelint-scales/blob/84d1d5b123a785b8642fe76f39ee940032c9090e/lib/rules/font-weights/index.js#L79-L85

However, a pull request is welcome to add this enhancement i.e. 400 and 700 are aliased as "normal" and "bold" behind the scenes. It'll involve reworking the findFontWeight function to find these nodes (taking into account that the font style can also be normal, e.g. font: normal normal 1em sans-serif;).

The rule would continue to autofix to the closest numeric values as people can use Stylelint's font-weight-notation to enforce keywords.

@jeddy3 jeddy3 added enhancement New feature or request help wanted Extra attention is needed labels Mar 7, 2022
@C0ZEN
Copy link
Author

C0ZEN commented Mar 8, 2022

I am willing to give it a try, when I come back from my holidays ;)

@jeddy3
Copy link
Owner

jeddy3 commented Mar 8, 2022

That'd be fantastic. You're welcome to open an early work-in-progress pull request as I can help you.

The rule will still expect an array of numbers, but 400 and 700 are aliased behind the scenes.

For example, given:

{
  "plugins": ["@signal-noise/stylelint-scales"],
  "rules": {
    "scales/font-weights": [400, 600],
  }
}

The following are both valid:

a { font-weight: 400; }
a { font-weight: normal; }

The following is invalid:

a { font-weight: 300; }

And will be corrected to:

a { font-weight: 400; }

(Which Stylelint's font-weight-notation rule, if using the "named-where-possible" option will say needs to be (add can be made to autofix: stylelint/stylelint#3158) the keyword equivalent).

Enjoy your holidays!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants