Skip to content

Commit be85d5a

Browse files
committed
feature(@putout/plugin-eslint) add convert-node-to-n
1 parent 962247e commit be85d5a

20 files changed

+170
-21
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"extends": [
3-
"plugin:node/recommended",
3+
"plugin:n/recommended",
44
"plugin:putout/recommended"
55
],
66
"plugins": [
7-
"node",
7+
"n",
88
"putout"
99
]
1010
}

packages/plugin-eslint/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ npm i @putout/plugin-eslint -D
2525
"eslint/move-putout-to-end-of-extends": "on",
2626
"eslint/convert-ide-to-safe": "on",
2727
"eslint/convert-require-to-import": "on",
28-
"eslint/convert-import-to-require": "on",
28+
"eslint/convert-node-to-n": "on",
2929
"eslint/remove-no-missing": "on",
3030
"eslint/remove-no-unpublished-require": "on",
3131
"eslint/remove-no-unsupported-features": "on",
@@ -271,6 +271,25 @@ And ofcourse remove only elements with empty `rules`:
271271
};
272272
```
273273

274+
## convert-node-to-n
275+
276+
`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).
277+
278+
```diff
279+
{
280+
"extends": [
281+
"plugin:putout/safe+align",
282+
- "plugin:node/recommended"
283+
+ "plugin:n/recommended"
284+
],
285+
"plugins": [
286+
"putout",
287+
- "node"
288+
+ "n"
289+
]
290+
}
291+
```
292+
274293
## remove-no-missing
275294

276295
`node/remove-no-missing-require` and `node/remove-no-missing-import` doesn't supports [`exports`](https://nodejs.org/dist/latest-v18.x/docs/api/packages.html#exports)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
__putout_processor_json({
2+
"extends": [
3+
'plugin:n/recommended',
4+
"plugin:putout/ide",
5+
],
6+
"plugins": [
7+
"putout",
8+
'n'
9+
]
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
__putout_processor_json({
2+
"extends": [
3+
"plugin:node/recommended",
4+
"plugin:putout/ide",
5+
],
6+
"plugins": [
7+
"putout",
8+
"node"
9+
]
10+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__putout_processor_json({
2+
"plugins": [
3+
"putout",
4+
'n'
5+
]
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
__putout_processor_json({
2+
"plugins": [
3+
"putout",
4+
"node"
5+
]
6+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
const {getExtends, getPlugins} = require('../get');
4+
5+
module.exports.report = () => 'Use "n" instead of "node"';
6+
7+
module.exports.match = () => ({
8+
'__putout_processor_json(__a)': ({__a}) => {
9+
const elements = getExtends(__a);
10+
const plugins = getPlugins(__a);
11+
12+
for (const {value} of elements) {
13+
if (value.includes('node/recommended'))
14+
return true;
15+
}
16+
17+
for (const {value} of plugins) {
18+
if (value === 'node')
19+
return true;
20+
}
21+
22+
return false;
23+
},
24+
});
25+
26+
module.exports.replace = () => ({
27+
'__putout_processor_json(__a)': ({__a}, path) => {
28+
const elements = getExtends(__a);
29+
const plugins = getPlugins(__a);
30+
31+
for (const element of elements) {
32+
const {value} = element;
33+
34+
if (value.includes('node/recommended'))
35+
element.value = 'plugin:n/recommended';
36+
}
37+
38+
for (const element of plugins) {
39+
const {value} = element;
40+
41+
if (value === 'node')
42+
element.value = 'n';
43+
}
44+
45+
return path;
46+
},
47+
});
48+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const {createTest} = require('@putout/test');
4+
const convertIdeToSafe = require('.');
5+
6+
const test = createTest(__dirname, {
7+
'eslint/convert-node-to-n': convertIdeToSafe,
8+
});
9+
10+
test('putout: plugin-eslint: convert-node-to-n: report', (t) => {
11+
t.report('node', 'Use "n" instead of "node"');
12+
t.end();
13+
});
14+
15+
test('putout: plugin-eslint: convert-node-to-n: transform', (t) => {
16+
t.transform('node');
17+
t.end();
18+
});
19+
20+
test('putout: plugin-eslint: convert-node-to-n: transform: plugins', (t) => {
21+
t.transform('plugins');
22+
t.end();
23+
});
24+

packages/plugin-eslint/lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports.rules = {
1010
...getRule('move-putout-to-end-of-extends'),
1111
...getRule('convert-ide-to-safe'),
1212
...getRule('convert-require-to-import'),
13+
...getRule('convert-node-to-n'),
1314
...getRule('remove-no-unpublished-require'),
1415
...getRule('remove-no-unsupported-features'),
1516
...getRule('remove-overrides-with-empty-rules'),

packages/plugin-eslint/test/eslint.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ test('putout: plugin-eslint: transform: add-putout', (t) => {
5757
t.end();
5858
});
5959

60+
test('putout: plugin-eslint: transform: convert-node-to-n', (t) => {
61+
t.transform('convert-node-to-n');
62+
t.end();
63+
});
64+

0 commit comments

Comments
 (0)