Skip to content

Latest commit

 

History

History
58 lines (46 loc) · 1.21 KB

fixer-return.md

File metadata and controls

58 lines (46 loc) · 1.21 KB

Require fixer functions to return a fix (fixer-return)

✔️ The "extends": "plugin:eslint-plugin/recommended" property in a configuration file enables this rule.

In a fixable rule, a fixer function is useless if it never returns anything.

Rule Details

This rule enforces that a fixer function returns a fix in at least one situation.

Examples of incorrect code for this rule:

/* eslint eslint-plugin/fixer-return: error */

module.exports = {
  create (context) {
    context.report({
      fix (fixer) {
        fixer.insertTextAfter(node, 'foo');
      },
    });
  },
};

Examples of correct code for this rule:

/* eslint eslint-plugin/fixer-return: error */

module.exports = {
  create (context) {
    context.report({
      fix (fixer) {
        return fixer.insertTextAfter(node, 'foo');
      },
    });
  },
};
/* eslint eslint-plugin/fixer-return: error */

module.exports = {
  create (context) {
    context.report({
      fix (fixer) {
        if (foo) {
          return; // no autofix in this situation
        }
        return fixer.insertTextAfter(node, 'foo');
      },
    });
  },
};