Skip to content

Latest commit

 

History

History
60 lines (47 loc) · 1.28 KB

fixer-return.md

File metadata and controls

60 lines (47 loc) · 1.28 KB

Require fixer functions to return a fix (eslint-plugin/fixer-return)

💼 This rule is enabled in the ✅ recommended config.

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