@putout/plugin-nodejs 2.0.1 → 3.0.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,22 @@
11
11
  npm i putout @putout/plugin-nodejs -D
12
12
  ```
13
13
 
14
- ## Rules
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-url": "on"
21
+ "nodejs/convert-dirname-to-url": "on",
22
+ "nodejs/remove-process-exit": "on"
22
23
  }
23
24
  }
24
25
  ```
25
26
 
26
- # convert-fs-promises
27
+ ## Rules
28
+
29
+ ### convert-fs-promises
27
30
 
28
31
  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
32
 
@@ -31,38 +34,38 @@ Convert [fs.promises](https://nodejs.org/dist/latest-v15.x/docs/api/fs.html#fs_f
31
34
  import {readFile} from 'fs/promises';
32
35
  ```
33
36
 
34
- ## ❌ Incorrect code example
37
+ #### ❌ Incorrect code example
35
38
 
36
39
  ```js
37
40
  const {readFile} = require('fs').promises;
38
41
  ```
39
42
 
40
- ## ✅ Correct code Example
43
+ #### ✅ Correct code Example
41
44
 
42
45
  ```js
43
46
  const {readFile} = require('fs/promises');
44
47
  ```
45
48
 
46
- # convert-promisify-to-fs-promises
49
+ ### convert-promisify-to-fs-promises
47
50
 
48
- ## ❌ Incorrect code example
51
+ #### ❌ Incorrect code example
49
52
 
50
53
  ```js
51
54
  const fs = require('fs');
52
55
  const readFile = promisify(fs.readFile);
53
56
  ```
54
57
 
55
- ## ✅ Correct code Example
58
+ #### ✅ Correct code Example
56
59
 
57
60
  ```js
58
61
  const {readFile} = require('fs/promises');
59
62
  ```
60
63
 
61
- # convert-dirname-to-url
64
+ ### convert-dirname-to-url
62
65
 
63
66
  Only for `EcmaScript Modules`.
64
67
 
65
- ## ❌ Incorrect code example
68
+ #### ❌ Incorrect code example
66
69
 
67
70
  ```js
68
71
  import {readFile} from 'fs/promises';
@@ -71,7 +74,7 @@ const file1 = join(__dirname, '../../package.json');
71
74
  const file2 = path.join(__dirname, '../../package.json');
72
75
  ```
73
76
 
74
- ## ✅ Correct code Example
77
+ #### ✅ Correct code Example
75
78
 
76
79
  ```js
77
80
  import {readFile} from 'fs/promises';
@@ -80,6 +83,23 @@ const file1 = new URL('../../package.json', import.meta.url);
80
83
  const file2 = new URL('../../package.json', import.meta.url);
81
84
  ```
82
85
 
86
+ ### convert-promisify-to-fs-promises
87
+
88
+ #### ❌ Incorrect code example
89
+
90
+ ```js
91
+ const fs = require('fs');
92
+ const readFile = promisify(fs.readFile);
93
+ ```
94
+
95
+ ### remove-process-exit
96
+
97
+ In most cases `process.exit()` is called from `bin` directory, if not - disable this rule using `match`.
98
+
99
+ ```diff
100
+ -process.exit();
101
+ ```
102
+
83
103
  ## License
84
104
 
85
105
  MIT
package/lib/index.js CHANGED
@@ -8,5 +8,6 @@ module.exports.rules = {
8
8
  ...getRule('convert-fs-promises'),
9
9
  ...getRule('convert-promisify-to-fs-promises'),
10
10
  ...getRule('convert-dirname-to-url'),
11
+ ...getRule('remove-process-exit'),
11
12
  };
12
13
 
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ module.exports.report = () => '"process.exit" should not be used';
4
+
5
+ module.exports.replace = () => ({
6
+ 'process.exit()': '',
7
+ 'process["exit"]()': '',
8
+ });
9
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "2.0.1",
3
+ "version": "3.0.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",
@@ -41,7 +41,7 @@
41
41
  "nodemon": "^2.0.1"
42
42
  },
43
43
  "peerDependencies": {
44
- "putout": ">=23"
44
+ "putout": ">=24"
45
45
  },
46
46
  "license": "MIT",
47
47
  "engines": {