Require suggestable rules to implement a meta.hasSuggestions
property (require-meta-has-suggestions)
✔️ The "extends": "plugin:eslint-plugin/recommended"
property in a configuration file enables this rule.
⚒️ The --fix
option on the command line can automatically fix some of the problems reported by this rule.
A suggestable ESLint rule should specify the meta.hasSuggestions
property with a value of true
. This makes it easier for both humans and tooling to tell whether a rule provides suggestions. As of ESLint 8, an exception will be thrown if a suggestable rule is missing this property.
Likewise, rules that do not report suggestions should not enable the meta.hasSuggestions
property.
This rule aims to require ESLint rules to have a meta.hasSuggestions
property if necessary.
Examples of incorrect code for this rule:
/* eslint eslint-plugin/require-meta-has-suggestions: "error" */
module.exports = {
meta: {}, // Missing `meta.hasSuggestions`.
create (context) {
context.report({
node,
message: 'foo',
suggest: [
{
desc: 'Insert space at the beginning',
fix: fixer => fixer.insertTextBefore(node, ' '),
},
],
});
},
};
/* eslint eslint-plugin/require-meta-has-suggestions: "error" */
module.exports = {
meta: { hasSuggestions: true }, // Has `meta.hasSuggestions` enabled but never provides suggestions.
create (context) {
context.report({
node,
message: 'foo',
});
},
};
Examples of correct code for this rule:
/* eslint eslint-plugin/require-meta-has-suggestions: "error" */
module.exports = {
meta: { hasSuggestions: true },
create (context) {
context.report({
node,
message: 'foo',
suggest: [
{
desc: 'Insert space at the beginning',
fix: fixer => fixer.insertTextBefore(node, ' '),
},
],
});
},
};
/* eslint eslint-plugin/require-meta-has-suggestions: "error" */
module.exports = {
meta: {},
create (context) {
context.report({
node,
message: 'foo',
});
},
};