Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.44 KB

prefer-object-rule.md

File metadata and controls

44 lines (32 loc) · 1.44 KB

Disallow function-style rules (prefer-object-rule)

✔️ 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.

Prior to ESLint v9, ESLint supported both function-style and object-style rules. However, function-style rules have been deprecated since 2016, and do not support newer features like autofixing and suggestions.

As of ESLint v9, ESLint supports only object-style rules.

Rule Details

The rule reports an error if it encounters a rule that's defined using the deprecated function-style format.

Examples of incorrect code for this rule:

/* eslint eslint-plugin/prefer-object-rule: error */

module.exports = function create(context) {
  return {
    Program() {
      context.report();
    },
  };
};

Examples of correct code for this rule:

/* eslint eslint-plugin/prefer-object-rule: error */

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