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 experimental support for custom message arguments #6312
Changes from 8 commits
f0ca0a6
4734421
eddbb4b
9d1ef44
4b11c6a
2cd9ae0
3eb141f
9d8e693
a38c74b
fb47cf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,31 @@ For example, the following rule configuration would substitute in custom message | |
|
||
Alternately, you can write a [custom formatter](../developer-guide/formatters.md) for maximum control if you need serious customization. | ||
|
||
Experimental feature: some rules support message arguments. For example, when configuring the `color-no-hex` rule the hex color can be used in message string: | ||
|
||
`.stylelintrc.js`: | ||
|
||
```js | ||
{ | ||
'color-no-hex': [true, { | ||
message: (hex) => `Don't use hex colors like "${hex}"`, | ||
}] | ||
} | ||
``` | ||
|
||
`.stylelintrc.json`: | ||
|
||
<!-- prettier-ignore --> | ||
```json | ||
{ | ||
"color-no-hex": [true, { | ||
"message": "Don't use hex colors like \"%s\"" | ||
}] | ||
} | ||
``` | ||
|
||
With formats that don't support a function like JSON, you can use a `printf`-like format (e.g., `%s`). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [note] I think a description of See also the |
||
|
||
### `reportDisables` | ||
|
||
You can set the `reportDisables` secondary option to report any `stylelint-disable` comments for this rule, effectively disallowing authors to opt out of it. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,8 @@ const rule = (primary) => { | |
const endIndex = index + node.value.length; | ||
|
||
report({ | ||
message: messages.rejected(node.value), | ||
message: messages.rejected, | ||
messageArgs: [node.value], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remark If I understand correctly, the order will be arbitrary. i.e.
related There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Mouvedia Thanks for the share. Other problems might be found than you pointed out, but this feature is still experimental. We would try considering it based on reactions or feedback later. |
||
node: decl, | ||
index, | ||
endIndex, | ||
|
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.
[note] Unless the disabling comment, Prettier would format the snippet like this:
Compared to the snippet above for
.stylelintrc.js
, it would not be easier to read.