Skip to content

[Bug]: flat config crash when using manual plugin def and recommended config #3693

Closed
@bradzacher

Description

@bradzacher

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

Repro

// eslint.config.js
import eslintReact from 'eslint-plugin-react';
import eslintReactRecommended from 'eslint-plugin-react/configs/recommended.js';

export default [
	{
		plugins: {
			react: eslintReact,
		},
	},
	eslintReactRecommended,
];

npx eslint eslint.config.js

Expected

No errors

Actual

Oops! Something went wrong! :(

ESLint: 8.56.0

Error: Key "plugins": Cannot redefine plugin "react".

More Info

When defining a plugin key in the flat config ESLint enforces that you only ever redefine they key with the same plugin. This check is done by comparing by reference -- i.e. configA.plugin.react === configB.plugin.react

eslint-plugin-react fails this check because it defines its "plugin" in two locations:

module.exports = {
deprecatedRules: configAll.plugins.react.deprecatedRules,
rules: allRules,
configs: {
recommended: Object.assign({}, configRecommended, {
parserOptions: configRecommended.languageOptions.parserOptions,
plugins,
}),
all: Object.assign({}, configAll, {
parserOptions: configAll.languageOptions.parserOptions,
plugins,
}),
'jsx-runtime': Object.assign({}, configRuntime, {
parserOptions: configRuntime.languageOptions.parserOptions,
plugins,
}),
},
};

react: {
deprecatedRules,
rules: allRules,
},

For this to work there needs to be exactly 1 copy of the "plugin" defined by the package.
For example:

const plugin = { ... };
plugin.configs = {
  recommended: {
    plugins: { react: plugin },
    rules: { ... },
  },
  all: {
    plugins: { react: plugin },
    rules: { ... },
  },
});

eslint-plugin-react version

v7.33.2

eslint version

v8.56.0

node version

v20.11.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions