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 autofix to font-weight-notation #6347

Merged
merged 3 commits into from Sep 18, 2022

Conversation

ybiquitous
Copy link
Member

@ybiquitous ybiquitous commented Sep 15, 2022

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

Closes #3158

Is there anything in the PR that needs further explanation?

I've refactored the rule implementation much to support autofix:

  • check each value node by the postcss-value-parser module
  • unify some logic between the font and font-weight properties (though a few conditional branches remain)
  • remove specific logic for the @font-face at-rule

Here is the code outline after the refactoring:

root.walkDecls(/^font(-weight)?$/i, (decl) => {
  const parsedValue = valueParser(getDeclarationValue(decl));

  for (const [index, valueNode] of valueNodes.entries()) {
    // checking each value node...
  }
});

@changeset-bot
Copy link

changeset-bot bot commented Sep 15, 2022

🦋 Changeset detected

Latest commit: 56863de

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

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

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

@ybiquitous ybiquitous force-pushed the add-autofix-to-font-weight-notation branch 3 times, most recently from 04c4ac7 to e71bcfe Compare September 15, 2022 01:35
@ybiquitous ybiquitous force-pushed the add-autofix-to-font-weight-notation branch from e71bcfe to efe5283 Compare September 15, 2022 01:41
@ybiquitous ybiquitous marked this pull request as ready for review September 15, 2022 01:46
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.

@ybiquitous This is a fantastic refactor to implement autofix, thank you!

I've thoughts on 3 things:

  1. Let's fix our references so they're accurate:

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,
);
  1. 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)".

  2. 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.

@ybiquitous
Copy link
Member Author

@jeddy3 Thanks for the review! I agree with your suggestions, and I've pushed the first refactoring via 56863de.

I'll work on the remaining suggestions on another PR to clarify the scope of this PR. 💪🏼

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.

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.

@ybiquitous ybiquitous merged commit 607a2d4 into main Sep 18, 2022
@ybiquitous ybiquitous deleted the add-autofix-to-font-weight-notation branch September 18, 2022 08:47
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.

Add autofix to font-weight-notation
2 participants