Skip to content

Latest commit

 

History

History
71 lines (57 loc) · 1.85 KB

File metadata and controls

71 lines (57 loc) · 1.85 KB

eslint-plugin/no-matching-violation-suggest-message-ids

📝 Require suggestions to have different messageId than their parent report.

When providing fix suggestions to a reported problem, it's important to have an actionable messageId for each suggestion rather than reusing the same messageId as the main report.

Rule Details

Examples of incorrect code for this rule:

/* eslint eslint-plugin/no-matching-violation-suggest-message-ids: error */

module.exports = {
  meta: { messages: { notAllowed: '`DebuggerStatement`s are not allowed' } },

  create(context) {
    return {
      DebuggerStatement(node) {
        context.report({
          node,
          messageId: 'notAllowed',
          suggest: [{ messageId: 'notAllowed' }],
        });
      },
    };
  },
};

Examples of correct code for this rule:

/* eslint eslint-plugin/no-matching-violation-suggest-message-ids: error */

module.exports = {
  meta: {
    messages: {
      notAllowed: '`DebuggerStatement`s are not allowed',
      remove: 'Remove the debugger statement',
    },
  },

  create(context) {
    return {
      DebuggerStatement(node) {
        context.report({
          node,
          messageId: 'notAllowed',
          suggest: [
            {
              messageId: 'remove',
              fix: (fixer) => fixer.remove(node),
            },
          ],
        });
      },
    };
  },
};

Further Reading