Skip to content

Commit b41677a

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

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

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

Lines changed: 34 additions & 0 deletions
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)