-
-
Notifications
You must be signed in to change notification settings - Fork 983
Add rule name to custom messages #8774
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 rule name to custom messages #8774
Conversation
🦋 Changeset detectedLatest commit: 0a199d6 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 |
@jhae-de Thanks for the pull request. I can't remember if this was an intentional design decision, as we added the We can either:
It seems the former leads to automated consistency, and the latter to choice. Let's see if any other maintainers have an opinion. Context: this is for the stylelint/lib/formatters/stringFormatter.mjs Lines 182 to 186 in 8d0b9d2
|
@jeddy3 Thanks for your feedback. I had also thought about which of the two approaches would be better beforehand. The decisive factor for me in the end was that the messages defined in the built-in rules are also automatically enriched with the rule names. Applying this to custom messages as well was the logical consequence for me. I am curious to hear what others think about this. |
@jhae-de Thank you for discovering and fixing the issue. I implemented the custom message feature, but this problem was out of my mind, sorry. First, let me show where the
Second, our default
So, to achieve consistency for problem messages, we may need to choose either of the two options below:
If we choose option 1, there is a little possibility of breaking, but its impact should not be significant. Instead, if we opt for option 2, it should be shipped in a major version. Personally, I'm leaning towards option 2 because I think it's verbose to contain {
"rule": "block-no-empty",
"text": "Unexpected empty block (block-no-empty)"
} As shown above, our default
To make custom formatters easier to implement, should we separate |
@ybiquitous Thank you for your feedback and some context regarding the rule messages. I hadn't actually thought about the option of removing the rule names from the messages altogether. At first, I didn't think the idea was so bad, as my main concern here was consistency. However, I would like to point out the following:
Output in PhpStorm: At least as far as point 2 is concerned, I always liked that the rule names were also displayed here. In this respect, I would personally find it regrettable if we were to remove the rule names from the messages in general. |
@jhae-de Thanks for the feedback, too! Regarding the About some IDEs, I didn't have any ideas before your comment, such as PhpStorm. Thank you for the info. I think it'd be more flexible to construct messages if I don't recall any requests for such flexibility having been submitted. Maybe, no requests. So now, it seems reasonable to me to add @jeddy3 Any thoughts? |
SGTM. In addition to IDEs like PhpStorm, the rulename is useful when Stylelint is used as a PostCSS plugin and postcss-reporter reports the warnings: We now recommend using our built-in formatters via the CLI or Node.js API, but some people may still be using the PostCSS plugin. |
This PR is packaged and the instant preview is available (0a199d6). View the demo website. Install it locally: npm i -D https://pkg.pr.new/stylelint@0a199d6 |
It looks to me as if this PR will be accepted. Is there anything else I need to do, such as generating the changeset? |
@jhae-de Yes, please add a changelog, respecting the PR title, e.g.: ---
"stylelint": minor
---
Added: rule name to custom messages |
f9fde25
to
2d11f2b
Compare
Ensures that when a custom message is specified in a Stylelint configuration, the rule name is automatically appended in parentheses at the end of the message if not already present, improving traceability of reported problems.
2d11f2b
to
0a199d6
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.
LGTM, thanks 👍🏼
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.
LGTM, thank you
| datasource | package | from | to | | ---------- | --------- | ------- | ------- | | npm | stylelint | 16.24.0 | 16.25.0 | ## [v16.25.0](https://github.com/stylelint/stylelint/blob/HEAD/CHANGELOG.md#16250---2025-10-03) It adds 3 new features, including experimental support for bulk suppressions. It's also our first [immutable release](https://github.blog/changelog/2025-08-26-releases-now-support-immutability-in-public-preview/), with the package published to npm using [trusted publishing](https://github.blog/changelog/2025-07-31-npm-trusted-publishing-with-oidc-is-generally-available/) and our dependencies updated on a [cool down](https://github.blog/changelog/2025-07-01-dependabot-supports-configuration-of-a-minimum-package-age/) for improved supply chain security. - Added: support for bulk suppressions ([#8564](stylelint/stylelint#8564)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `ignoreAtRules: []` to `no-invalid-position-declaration` ([#8781](stylelint/stylelint#8781)) ([@jrmlt](https://github.com/jrmlt)). - Added: rule name to custom messages ([#8774](stylelint/stylelint#8774)) ([@jhae-de](https://github.com/jhae-de)).
| datasource | package | from | to | | ---------- | --------- | ------- | ------- | | npm | stylelint | 16.24.0 | 16.25.0 | ## [v16.25.0](https://github.com/stylelint/stylelint/blob/HEAD/CHANGELOG.md#16250---2025-10-03) It adds 3 new features, including experimental support for bulk suppressions. It's also our first [immutable release](https://github.blog/changelog/2025-08-26-releases-now-support-immutability-in-public-preview/), with the package published to npm using [trusted publishing](https://github.blog/changelog/2025-07-31-npm-trusted-publishing-with-oidc-is-generally-available/) and our dependencies updated on a [cool down](https://github.blog/changelog/2025-07-01-dependabot-supports-configuration-of-a-minimum-package-age/) for improved supply chain security. - Added: support for bulk suppressions ([#8564](stylelint/stylelint#8564)) ([@ryo-manba](https://github.com/ryo-manba)). - Added: `ignoreAtRules: []` to `no-invalid-position-declaration` ([#8781](stylelint/stylelint#8781)) ([@jrmlt](https://github.com/jrmlt)). - Added: rule name to custom messages ([#8774](stylelint/stylelint#8774)) ([@jhae-de](https://github.com/jhae-de)).
This pull request improves the handling of custom error messages in a Stylelint configuration. It ensures that when a custom error message is specified in a Stylelint configuration, the rule name is automatically appended in parentheses at the end of the message if not already present.
Closes #8773
When a custom message is defined for a rule, such as for the
custom-property-pattern
rule:the rule name is now automatically appended in parentheses at the end of the message if it is not already present. This makes it easier to identify the source rule for each reported problem and improves traceability. Existing messages that already include the rule name remain unchanged.
Before:
After: