Skip to content

Commit 1ede445

Browse files
committed
feature: @putout/plugin-eslint: remove-spread-from-create-eslint-config: add
1 parent 4f91f11 commit 1ede445

File tree

10 files changed

+84
-5
lines changed

10 files changed

+84
-5
lines changed

packages/plugin-eslint/README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ npm i @putout/plugin-eslint -D
3939
-[remove-useless-slice](#remove-useless-slice);
4040
-[remove-useless-properties](#remove-useless-properties);
4141
-[remove-parser-options](#remove-parser-options);
42+
-[remove-spread-from-create-eslint-config](#remove-spread-from-create-eslint-config);
4243

4344
## Config
4445

@@ -68,7 +69,8 @@ npm i @putout/plugin-eslint -D
6869
"eslint/remove-overrides-with-empty-rules": "on",
6970
"eslint/remove-useless-slice": "on",
7071
"eslint/remove-useless-properties": "on",
71-
"eslint/remove-parser-options": "on"
72+
"eslint/remove-parser-options": "on",
73+
"eslint/remove-spread-from-create-eslint-config": "on"
7274
}
7375
}
7476
```
@@ -492,6 +494,25 @@ const ruleTester = new RuleTester({
492494
});
493495
```
494496
497+
## remove-spread-from-create-eslint-config
498+
499+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/1e10683f0f1fbb6f5b3dd23a940b316c/6274c36dfa69a98e640e2ee1cdd5bfcbf52d36ee).
500+
501+
### ❌ Example of incorrect code
502+
503+
```js
504+
export default createESLintConfig([
505+
safeAlign,
506+
...matchToFlat(match),
507+
]);
508+
```
509+
510+
### ✅ Example of correct code
511+
512+
```js
513+
export default createESLintConfig([safeAlign, matchToFlat(match)]);
514+
```
515+
495516
## convert-node-to-n
496517
497518
`eslint-plugin-node` [is no longer supported](https://github.com/mysticatea/eslint-plugin-node/issues/300). Better to use [`eslint-plugin-n`](https://github.com/weiran-zsd/eslint-plugin-node).

packages/plugin-eslint/lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const removeUselessProperties = require('./remove-useless-properties');
2222
const applyIgnores = require('./apply-ignores');
2323
const applyCreateEslintConfig = require('./apply-create-eslint-config');
2424
const removeParserOptions = require('./remove-parser-options');
25+
const removeSpreadFromCreateEslintConfig = require('./remove-spread-from-create-eslint-config');
2526

2627
module.exports.rules = {
2728
'add-putout': addPutout,
@@ -46,4 +47,5 @@ module.exports.rules = {
4647
'apply-ignores': ['off', applyIgnores],
4748
'apply-create-eslint-config': applyCreateEslintConfig,
4849
'remove-parser-options': removeParserOptions,
50+
'remove-spread-from-create-eslint-config': removeSpreadFromCreateEslintConfig,
4951
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default createESLintConfig([safeAlign, matchToFlat(match)]);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default createESLintConfig([
2+
safeAlign,
3+
...matchToFlat(match),
4+
]);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const {types, operator} = require('putout');
4+
const {isSpreadElement} = types;
5+
const {replaceWith} = operator;
6+
7+
module.exports.report = () => `Avoid spread ('...') in 'createEslintConfig'`;
8+
9+
module.exports.fix = (path) => {
10+
replaceWith(path, path.node.argument);
11+
};
12+
13+
module.exports.traverse = ({push}) => ({
14+
'createESLintConfig(__array)'(path) {
15+
for (const argPath of path.get('arguments.0.elements')) {
16+
if (isSpreadElement(argPath))
17+
push(argPath);
18+
}
19+
},
20+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const {createTest} = require('@putout/test');
4+
const plugin = require('.');
5+
6+
const test = createTest(__dirname, {
7+
plugins: [
8+
['remove-spread-from-create-eslint-config', plugin],
9+
],
10+
});
11+
12+
test('eslint: remove-spread-from-create-eslint-config: report', (t) => {
13+
t.report('remove-spread-from-create-eslint-config', `Avoid spread ('...') in 'createEslintConfig'`);
14+
t.end();
15+
});
16+
17+
test('eslint: remove-spread-from-create-eslint-config: transform', (t) => {
18+
t.transform('remove-spread-from-create-eslint-config');
19+
t.end();
20+
});

packages/plugin-eslint/test/eslint.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,8 @@ test('plugin-eslint: transform: remove-parser-options', (t) => {
123123
t.transform('remove-parser-options');
124124
t.end();
125125
});
126+
127+
test('plugin-eslint: transform: remove-spread-from-create-eslint-config', (t) => {
128+
t.transform('remove-spread-from-create-eslint-config');
129+
t.end();
130+
});

packages/plugin-eslint/test/fixture/apply-match-to-flat-fix.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,4 @@ export const match = {
1111
'node/no-extraneous-import': 'off',
1212
},
1313
};
14-
export default createESLintConfig([
15-
safeAlign,
16-
...matchToFlat(match),
17-
]);
14+
export default createESLintConfig([safeAlign, matchToFlat(match)]);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {createESLintConfig} from '@putout/eslint-flat';
2+
import {safeAlign} from 'eslint-plugin-putout/config';
3+
import {matchToFlat} from '@putout/eslint-flat';
4+
5+
export default createESLintConfig([safeAlign, matchToFlat(match)]);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default createESLintConfig([
2+
safeAlign,
3+
...matchToFlat(match),
4+
]);

0 commit comments

Comments
 (0)