Skip to content

Latest commit

 

History

History
94 lines (70 loc) · 2.3 KB

require-meta-has-suggestions.md

File metadata and controls

94 lines (70 loc) · 2.3 KB

require suggestable rules to implement a meta.hasSuggestions property (require-meta-has-suggestions)

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.

The following patterns are considered warnings:

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

The following patterns are not warnings:

/* 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