Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b41677a

Browse filesBrowse files
mdjermanovicplatinumazure
authored andcommitted
Docs: Clarify suggestion's data in Working with Rules (refs #12606) (#12617)
1 parent ea16de4 commit b41677a
Copy full SHA for b41677a

File tree

Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+34
-0
lines changed
Open diff view settings
Collapse file

‎docs/developer-guide/working-with-rules.md‎

Copy file name to clipboardExpand all lines: docs/developer-guide/working-with-rules.md
+34Lines changed: 34 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,40 @@ module.exports = {
418418
};
419419
```
420420
421+
#### Placeholders in suggestion messages
422+
423+
You can also use placeholders in the suggestion message. This works the same way as placeholders for the overall error (see [using message placeholders](#using-message-placeholders)).
424+
425+
Please note that you have to provide `data` on the suggestion's object. Suggestion messages cannot use properties from the overall error's `data`.
426+
427+
```js
428+
module.exports = {
429+
meta: {
430+
messages: {
431+
unnecessaryEscape: "Unnecessary escape character: \\{{character}}.",
432+
removeEscape: "Remove `\\` before {{character}}.",
433+
}
434+
},
435+
create: function(context) {
436+
// ...
437+
context.report({
438+
node: node,
439+
messageId: "unnecessaryEscape",
440+
data: { character }, // data for the unnecessaryEscape overall message
441+
suggest: [
442+
{
443+
messageId: "removeEscape",
444+
data: { character }, // data for the removeEscape suggestion message
445+
fix: function(fixer) {
446+
return fixer.removeRange(range);
447+
}
448+
}
449+
]
450+
});
451+
}
452+
};
453+
```
454+
421455
### context.options
422456
423457
Some rules require options in order to function correctly. These options appear in configuration (`.eslintrc`, command line, or in comments). For example:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.