Skip to content

Latest commit

 

History

History
92 lines (73 loc) · 2.63 KB

require-meta-has-suggestions.md

File metadata and controls

92 lines (73 loc) · 2.63 KB

Require suggestable rules to implement a meta.hasSuggestions property (eslint-plugin/require-meta-has-suggestions)

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

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.

Rule Details

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',
    });
  },
};

Further Reading