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 autofix to font-weight-notation
#6347
Conversation
🦋 Changeset detectedLatest commit: 56863de The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
04c4ac7
to
e71bcfe
Compare
e71bcfe
to
efe5283
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ybiquitous This is a fantastic refactor to implement autofix, thank you!
I've thoughts on 3 things:
- Let's fix our references so they're accurate:
stylelint/lib/reference/keywords.js
Line 31 in efe5283
const fontWeightAbsoluteKeywords = new Set(['bold']); |
This set should be: ["normal", "bold"]
And then let's unite the sets in the reference file (rather than the rule itself), e.g.
const fontWeightNonNumericKeywords = uniteSets(
fontWeightRelativeKeywords,
fontWeightAbsoluteKeywords,
);
const fontWeightKeywords = uniteSets(
basicKeywords,
fontWeightNonNumericKeywords,
fontWeightNumericKeywords,
);
-
We generally use the format "Expected x to be y" when a rule supports autofixing of small things, e.g. "Expected '400' to be 'normal' (font-weight-notation)".
-
While we're refactoring we may want to remove the validation path, i.e.:
invalidNamed: (name) => `Unexpected invalid font-weight name "${name}"`,
The rule should only be doing one thing.
Shall we do the latter two suggestions in this pull request or in follow-up ones? The latter one may make the refactor even cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for implementing the first suggestion.
PR LGTM. Feel free to merge.
I'll work on the remaining suggestions on another PR to clarify the scope of this PR. 💪🏼
SGTM.
Closes #3158
I've refactored the rule implementation much to support autofix:
postcss-value-parser
modulefont
andfont-weight
properties (though a few conditional branches remain)@font-face
at-ruleHere is the code outline after the refactoring: