Skip to content

Commit

Permalink
Docs: Clarify suggestion's data in Working with Rules (refs #12606) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored and platinumazure committed Nov 29, 2019
1 parent ea16de4 commit b41677a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docs/developer-guide/working-with-rules.md
Expand Up @@ -418,6 +418,40 @@ module.exports = {
};
```

#### Placeholders in suggestion messages

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)).

Please note that you have to provide `data` on the suggestion's object. Suggestion messages cannot use properties from the overall error's `data`.

```js
module.exports = {
meta: {
messages: {
unnecessaryEscape: "Unnecessary escape character: \\{{character}}.",
removeEscape: "Remove `\\` before {{character}}.",
}
},
create: function(context) {
// ...
context.report({
node: node,
messageId: "unnecessaryEscape",
data: { character }, // data for the unnecessaryEscape overall message
suggest: [
{
messageId: "removeEscape",
data: { character }, // data for the removeEscape suggestion message
fix: function(fixer) {
return fixer.removeRange(range);
}
}
]
});
}
};
```

### context.options

Some rules require options in order to function correctly. These options appear in configuration (`.eslintrc`, command line, or in comments). For example:
Expand Down

0 comments on commit b41677a

Please sign in to comment.