@putout/plugin-nodejs 3.0.1 → 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
@@ -19,6 +19,7 @@ npm i putout @putout/plugin-nodejs -D
19
19
  "nodejs/convert-fs-promises": "on",
20
20
  "nodejs/convert-promisify-to-fs-promises": "on",
21
21
  "nodejs/convert-dirname-to-url": "on",
22
+ "nodejs/convert-top-level-return": "on",
22
23
  "nodejs/remove-process-exit": "on"
23
24
  }
24
25
  }
@@ -91,6 +92,20 @@ In most cases `process.exit()` is called from `bin` directory, if not - disable
91
92
  -process.exit();
92
93
  ```
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
+
94
109
  ## License
95
110
 
96
111
  MIT
@@ -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
@@ -8,6 +8,7 @@ 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('convert-top-level-return'),
11
12
  ...getRule('remove-process-exit'),
12
13
  };
13
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-nodejs",
3
- "version": "3.0.1",
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,7 +35,7 @@
35
35
  "c8": "^7.5.0",
36
36
  "eslint": "^8.0.1",
37
37
  "eslint-plugin-node": "^11.0.0",
38
- "eslint-plugin-putout": "^12.0.0",
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"