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

Use parameterized custom messages #263

Closed
ybiquitous opened this issue Oct 3, 2022 · 1 comment · Fixed by #264
Closed

Use parameterized custom messages #263

ybiquitous opened this issue Oct 3, 2022 · 1 comment · Fixed by #264
Labels
status: ask to implement ask before implementing as may no longer be relevant type: enhancement a new feature that isn't related to rules

Comments

@ybiquitous
Copy link
Member

What is the problem you're trying to solve?

This sharable config stylelint-config-standard has defined a custom message for a few rules, for example of the selector-class-pattern:

'selector-class-pattern': [
'^([a-z][a-z0-9]*)(-[a-z0-9]+)*$',
{
message: 'Expected class selector to be kebab-case',
},
],

A custom message (demo):

Expected class selector to be kebab-case

An original message (demo):

Expected class selector ".FOO" to match pattern "^([a-z][a-z0-9]*)(-[a-z0-9]+)*$"

It would seem more useful if the custom message would become as below:

Expected class selector ".FOO" to be kebab-case

What solution would you like to see?

We have added the experimental feature for custom message formatting via stylelint/stylelint#6312 and the 14.12.0 version, so we can use it here.

I suggest like this:

- message: 'Expected class selector to be kebab-case',
+ message: (value) => `Expected class selector "${value}" to be kebab-case`,

Also, we need to update the built-in rules to enable the custom formatting for the rules using a custom message in stylelint-config-standard. Like this:

- message: messages.expected(selector, primary),
+ message: messages.expected,
+ messageArgs: [selector, primary],

See also the built-in rule code.

Target rules can be as below:

  • custom-media-pattern
  • custom-property-pattern
  • keyframes-name-pattern
  • selector-class-pattern
  • selector-id-pattern
@ybiquitous ybiquitous added the status: needs discussion triage needs further discussion label Oct 3, 2022
@jeddy3
Copy link
Member

jeddy3 commented Oct 3, 2022

Sounds great to me!

@jeddy3 jeddy3 added type: enhancement a new feature that isn't related to rules status: ask to implement ask before implementing as may no longer be relevant and removed status: needs discussion triage needs further discussion labels Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ask to implement ask before implementing as may no longer be relevant type: enhancement a new feature that isn't related to rules
Development

Successfully merging a pull request may close this issue.

2 participants