Skip to content

Commit

Permalink
[Fix] ensure stable plugin reference with flat configs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bradzacher authored and ljharb committed Nov 15, 2024
1 parent d32edac commit 53ca775
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions __tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@ test('schemas', (t) => {

t.end();
});

test('plugin referentially equal to prevent flat config issues', (t) => {
const keys = Object.keys(plugin.flatConfigs);
for (let i = 0; i < keys.length; i += 1) {
const config = plugin.flatConfigs[keys[i]];
t.equal(plugin, config.plugins['jsx-a11y'], `${config.name}'s plugin reference is referentially equal to the top-level export`);
}
t.end();
});
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,4 @@ const flatConfigs = {
strict: createConfig(strictRules, 'strict'),
};

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

0 comments on commit 53ca775

Please sign in to comment.