Skip to content

Commit 53ca775

Browse files
bradzacherljharb
authored andcommitted
[Fix] ensure stable plugin reference with flat configs
The previous use of spread meant that ```ts import jsxA11y from 'eslint-plugin-jsx-a11y'; jsxA11y !== jsxA11y.flatConfigs.recommended.plugins['jsx-a11y'] ``` This is a problem because if someone does something like this ```js import jsxA11y from 'eslint-plugin-jsx-a11y'; export default [ { plugins: { 'jsx-a11y': jsxA11y } }, jsxA11y.flatConfigs.recommended, ]; ``` then ESLint will crash with the error `Config "jsx-a11y/recommended": Key "plugins": Cannot redefine plugin "jsx-a11y".` This PR fixes that by using `Object.assign` to mutate the `jsxA11y` object and maintain referential equality.
1 parent d32edac commit 53ca775

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

__tests__/index-test.js

+9
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,12 @@ test('schemas', (t) => {
3838

3939
t.end();
4040
});
41+
42+
test('plugin referentially equal to prevent flat config issues', (t) => {
43+
const keys = Object.keys(plugin.flatConfigs);
44+
for (let i = 0; i < keys.length; i += 1) {
45+
const config = plugin.flatConfigs[keys[i]];
46+
t.equal(plugin, config.plugins['jsx-a11y'], `${config.name}'s plugin reference is referentially equal to the top-level export`);
47+
}
48+
t.end();
49+
});

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,4 @@ const flatConfigs = {
317317
strict: createConfig(strictRules, 'strict'),
318318
};
319319

320-
module.exports = { ...jsxA11y, configs, flatConfigs };
320+
module.exports = Object.assign(jsxA11y, { configs, flatConfigs });

0 commit comments

Comments
 (0)