Skip to content

Latest commit

 

History

History
48 lines (35 loc) · 1.49 KB

prefer-object-rule.md

File metadata and controls

48 lines (35 loc) · 1.49 KB

Disallow function-style rules (eslint-plugin/prefer-object-rule)

💼 This rule is enabled in the ✅ recommended config.

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

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