Skip to content

Latest commit

History

History
67 lines (49 loc) 路 1.88 KB

File metadata and controls

67 lines (49 loc) 路 1.88 KB

eslint-plugin/require-meta-languages

馃摑 Require rules to implement a meta.languages property.

ESLint v10.2.0 introduced meta.languages to declare which languages a rule supports, using plugin-prefixed identifiers such as 'js/js' or 'json/json'.

When meta.languages is omitted, ESLint assumes the rule supports every language. This assumption is incorrect for almost all rules: a rule written for JavaScript can crash on an unfamiliar JSON or CSS AST, or silently do nothing. Declaring meta.languages allows ESLint to report a clear configuration-time error instead.

Dynamically computed values and unresolved spreads in meta are skipped, matching the behavior of the other require-meta-* rules.

Rule Details

This rule requires ESLint rules to have a non-empty meta.languages array whose entries are valid language identifiers: either the '*' wildcard or a 'namespace/language' form (such as 'js/js', 'json/json', or 'markdown/*'), with no duplicates.

Examples of incorrect code for this rule:

/* eslint eslint-plugin/require-meta-languages: error */

module.exports = {
  meta: {},
  create(context) {
    /* ... */
  },
};

module.exports = {
  meta: { languages: ['javascript'] },
  create(context) {
    /* ... */
  },
};

module.exports = {
  meta: { languages: ['js/js', 'js/js'] },
  create(context) {
    /* ... */
  },
};

Examples of correct code for this rule:

/* eslint eslint-plugin/require-meta-languages: error */

module.exports = {
  meta: { languages: ['js/js'] },
  create(context) {
    /* ... */
  },
};

module.exports = {
  meta: { languages: ['markdown/*'] },
  create(context) {
    /* ... */
  },
};

Further Reading