Skip to content

Latest commit

 

History

History
63 lines (49 loc) · 1.47 KB

prefer-object-rule.md

File metadata and controls

63 lines (49 loc) · 1.47 KB

Disallow rule exports where the export is a function (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.

Rule Details

The rule reports an error if it encounters a rule that's defined using the deprecated style of just a create function instead of the newer object style.

Examples of incorrect code for this rule:

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

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

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

module.exports = context => {
  return { Program () {
    context.report();
  } };
};

Examples of correct code for this rule:

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

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

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

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