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

Fix messages of font-weight-notation #6350

Merged
merged 5 commits into from Sep 19, 2022

Conversation

ybiquitous
Copy link
Member

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

Follow-up of #6347 (review)

Is there anything in the PR that needs further explanation?

This PR includes the following changes:

  • Use the "Expected x to be y" message format as possible
  • Remove the message for invalid font-weight notations
    (it's possible to use the stylelint-csstree-validator package instead)

@changeset-bot
Copy link

changeset-bot bot commented Sep 18, 2022

🦋 Changeset detected

Latest commit: e109761

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

- Use the "Expected x to be y" message format as possible
- Remove the message for invalid `font-weight` notations
  (it's possible to use the `stylelint-csstree-validator` package instead)
@ybiquitous ybiquitous force-pushed the fix-messages-of-font-weight-notation branch from a56e047 to ff585bf Compare September 18, 2022 09:21

const ruleName = 'font-weight-notation';

const messages = ruleMessages(ruleName, {
expected: (type) => `Expected ${type} font-weight notation`,
expectedWithActual: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] Add expectedWithActual for backward compatibility.

Copy link
Member

Choose a reason for hiding this comment

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

You're right to add this.

When we first built the rule, it should have only checked normal and bold rather than relative words too. Now we have an odd mix of the named-where-possible and numeric primary options along with the ignore: ["relative"] secondary option.

It's too late to change it now.

Adding expectedWithActual is the best way to deal with backwards compatibility for things like:

{
code: 'a { font: italic small-caps bolder 16px/3 cursive; }',
unfixable: true,
message: messages.expected('numeric'),
line: 1,
column: 29,
endLine: 1,
endColumn: 35,
},

['normal', '400'],
['bold', '700'],
]);
const NUMERIC_TO_KEYWORD = new Map([
const NUMERIC_TO_NAMED = new Map([
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] Rename for more accuracy because both 400 and normal are keywords.

if (keyword) {
weightValueNode.value = keyword;
}
assertString(namedValue);
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] Use assertString for less if branches. NUMERIC_TO_NAMED.has() === true ensures the return value of NUMERIC_TO_NAMED.get() is a string.

@ybiquitous ybiquitous marked this pull request as ready for review September 18, 2022 09:28
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 this!

We should also remove this line from the rule README and list of rule docs:

"Also, when named values are expected, require only valid names."

And this line from the rule README:

"Valid font-weight names are normal, bold, bolder, and lighter."

.changeset/wicked-wombats-look.md Show resolved Hide resolved
lib/rules/font-weight-notation/index.js Outdated Show resolved Hide resolved

const ruleName = 'font-weight-notation';

const messages = ruleMessages(ruleName, {
expected: (type) => `Expected ${type} font-weight notation`,
expectedWithActual: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
Copy link
Member

Choose a reason for hiding this comment

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

You're right to add this.

When we first built the rule, it should have only checked normal and bold rather than relative words too. Now we have an odd mix of the named-where-possible and numeric primary options along with the ignore: ["relative"] secondary option.

It's too late to change it now.

Adding expectedWithActual is the best way to deal with backwards compatibility for things like:

{
code: 'a { font: italic small-caps bolder 16px/3 cursive; }',
unfixable: true,
message: messages.expected('numeric'),
line: 1,
column: 29,
endLine: 1,
endColumn: 35,
},

@ybiquitous
Copy link
Member Author

@jeddy3 Thanks for the review. I’ve addressed your suggestions.

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.

LGTM, thank you!

@ybiquitous ybiquitous merged commit 6edbbdf into main Sep 19, 2022
@ybiquitous ybiquitous deleted the fix-messages-of-font-weight-notation branch September 19, 2022 13:02
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.

None yet

2 participants