@putout/plugin-nodejs 2.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -11,19 +11,23 @@
|
|
|
11
11
|
npm i putout @putout/plugin-nodejs -D
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## Options
|
|
15
15
|
|
|
16
16
|
```json
|
|
17
17
|
{
|
|
18
18
|
"rules": {
|
|
19
19
|
"nodejs/convert-fs-promises": "on",
|
|
20
20
|
"nodejs/convert-promisify-to-fs-promises": "on",
|
|
21
|
-
"nodejs/convert-dirname-to-
|
|
21
|
+
"nodejs/convert-dirname-to-url": "on",
|
|
22
|
+
"nodejs/convert-top-level-return": "on",
|
|
23
|
+
"nodejs/remove-process-exit": "on"
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
## Rules
|
|
29
|
+
|
|
30
|
+
### convert-fs-promises
|
|
27
31
|
|
|
28
32
|
Convert [fs.promises](https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_fs_promises_api) into form that will be simpler to use and convert from in `ESM` to:
|
|
29
33
|
|
|
@@ -31,38 +35,38 @@ Convert [fs.promises](https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_f
|
|
|
31
35
|
import {readFile} from 'fs/promises';
|
|
32
36
|
```
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
#### ❌ Incorrect code example
|
|
35
39
|
|
|
36
40
|
```js
|
|
37
41
|
const {readFile} = require('fs').promises;
|
|
38
42
|
```
|
|
39
43
|
|
|
40
|
-
|
|
44
|
+
#### ✅ Correct code Example
|
|
41
45
|
|
|
42
46
|
```js
|
|
43
47
|
const {readFile} = require('fs/promises');
|
|
44
48
|
```
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
### convert-promisify-to-fs-promises
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
#### ❌ Incorrect code example
|
|
49
53
|
|
|
50
54
|
```js
|
|
51
55
|
const fs = require('fs');
|
|
52
56
|
const readFile = promisify(fs.readFile);
|
|
53
57
|
```
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
#### ✅ Correct code Example
|
|
56
60
|
|
|
57
61
|
```js
|
|
58
62
|
const {readFile} = require('fs/promises');
|
|
59
63
|
```
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
### convert-dirname-to-url
|
|
62
66
|
|
|
63
67
|
Only for `EcmaScript Modules`.
|
|
64
68
|
|
|
65
|
-
|
|
69
|
+
#### ❌ Incorrect code example
|
|
66
70
|
|
|
67
71
|
```js
|
|
68
72
|
import {readFile} from 'fs/promises';
|
|
@@ -71,7 +75,7 @@ const file1 = join(__dirname, '../../package.json');
|
|
|
71
75
|
const file2 = path.join(__dirname, '../../package.json');
|
|
72
76
|
```
|
|
73
77
|
|
|
74
|
-
|
|
78
|
+
#### ✅ Correct code Example
|
|
75
79
|
|
|
76
80
|
```js
|
|
77
81
|
import {readFile} from 'fs/promises';
|
|
@@ -80,6 +84,28 @@ const file1 = new URL('../../package.json', import.meta.url);
|
|
|
80
84
|
const file2 = new URL('../../package.json', import.meta.url);
|
|
81
85
|
```
|
|
82
86
|
|
|
87
|
+
### remove-process-exit
|
|
88
|
+
|
|
89
|
+
In most cases `process.exit()` is called from `bin` directory, if not - disable this rule using `match`.
|
|
90
|
+
|
|
91
|
+
```diff
|
|
92
|
+
-process.exit();
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### convert-top-level-return
|
|
96
|
+
|
|
97
|
+
#### ❌ Incorrect code example
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
return;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### ✅ Correct code Example
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
process.exit();
|
|
107
|
+
```
|
|
108
|
+
|
|
83
109
|
## License
|
|
84
110
|
|
|
85
111
|
MIT
|
|
@@ -8,6 +8,6 @@ module.exports.report = () => `Use 'import.meta.url' instead of '__dirname'`;
|
|
|
8
8
|
module.exports.filter = isESM;
|
|
9
9
|
|
|
10
10
|
module.exports.replace = () => ({
|
|
11
|
-
'join(__dirname, __a)': 'new URL(__a, import.meta.url)',
|
|
12
|
-
'path.join(__dirname, __a)': 'new URL(__a, import.meta.url)',
|
|
11
|
+
'join(__dirname, __a)': 'new URL(__a, import.meta.url).pathname',
|
|
12
|
+
'path.join(__dirname, __a)': 'new URL(__a, import.meta.url).pathname',
|
|
13
13
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('putout');
|
|
4
|
+
const {isFunction} = types;
|
|
5
|
+
|
|
6
|
+
module.exports.report = () => `"process.exit" should be used instead of top-level return`;
|
|
7
|
+
|
|
8
|
+
module.exports.filter = (path) => !path.findParent(isFunction);
|
|
9
|
+
|
|
10
|
+
module.exports.replace = () => ({
|
|
11
|
+
'return __a()': '{__a(); process.exit()}',
|
|
12
|
+
'return __a': 'process.exit()',
|
|
13
|
+
'return': 'process.exit()',
|
|
14
|
+
});
|
|
15
|
+
|
package/lib/index.js
CHANGED
|
@@ -7,5 +7,8 @@ const getRule = (a) => ({
|
|
|
7
7
|
module.exports.rules = {
|
|
8
8
|
...getRule('convert-fs-promises'),
|
|
9
9
|
...getRule('convert-promisify-to-fs-promises'),
|
|
10
|
+
...getRule('convert-dirname-to-url'),
|
|
11
|
+
...getRule('convert-top-level-return'),
|
|
12
|
+
...getRule('remove-process-exit'),
|
|
10
13
|
};
|
|
11
14
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-nodejs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "putout plugin adds ability to transform code to new API of Node.js",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"c8": "^7.5.0",
|
|
36
36
|
"eslint": "^8.0.1",
|
|
37
37
|
"eslint-plugin-node": "^11.0.0",
|
|
38
|
-
"eslint-plugin-putout": "^
|
|
38
|
+
"eslint-plugin-putout": "^13.0.0",
|
|
39
39
|
"lerna": "^4.0.0",
|
|
40
40
|
"madrun": "^8.0.1",
|
|
41
41
|
"nodemon": "^2.0.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"putout": ">=
|
|
44
|
+
"putout": ">=24"
|
|
45
45
|
},
|
|
46
46
|
"license": "MIT",
|
|
47
47
|
"engines": {
|