@putout/plugin-return 3.0.0 → 4.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 +23 -0
- package/lib/index.js +2 -0
- package/lib/remove-last-empty/index.js +28 -0
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ npm i putout @putout/plugin-return -D
|
|
|
22
22
|
- ✅ [convert-from-break](#convert-from-continue);
|
|
23
23
|
- ✅ [merge-with-next-sibling](#merge-with-next-sibling);
|
|
24
24
|
- ✅ [remove-useless](#remove-useless);
|
|
25
|
+
- ✅ [remove-last-empty](#remove-last-empty);
|
|
25
26
|
- ✅ [simplify-boolean](#simplify-boolean);
|
|
26
27
|
|
|
27
28
|
## Config
|
|
@@ -34,6 +35,7 @@ npm i putout @putout/plugin-return -D
|
|
|
34
35
|
"return/convert-from-break": "on",
|
|
35
36
|
"return/merge-with-next-sibling": "on",
|
|
36
37
|
"return/remove-useless": "on",
|
|
38
|
+
"return/remove-last-empty": "on",
|
|
37
39
|
"return/simplify-boolean": "on"
|
|
38
40
|
}
|
|
39
41
|
}
|
|
@@ -198,6 +200,27 @@ const traverse = ({push}) => ({
|
|
|
198
200
|
});
|
|
199
201
|
```
|
|
200
202
|
|
|
203
|
+
### remove-last-empty
|
|
204
|
+
|
|
205
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/111549a3e6d61f8637ea12217062ea80/10e7842f9fbbf7fb0712d3b41cdcc707ae410fe5).
|
|
206
|
+
|
|
207
|
+
### ❌ Example of incorrect code
|
|
208
|
+
|
|
209
|
+
```js
|
|
210
|
+
const exit = (vars, path, {push}) => {
|
|
211
|
+
push(path);
|
|
212
|
+
return;
|
|
213
|
+
};
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### ✅ Example of correct code
|
|
217
|
+
|
|
218
|
+
```js
|
|
219
|
+
const exit = (vars, path, {push}) => {
|
|
220
|
+
push(path);
|
|
221
|
+
};
|
|
222
|
+
```
|
|
223
|
+
|
|
201
224
|
## simplify-boolean
|
|
202
225
|
|
|
203
226
|
Check out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/304035b9529830cf20e76e9a1f35f14c/39c743921c6bfad3984a3989f25c2986ab51e8c8).
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as removeLastEmpty from './remove-last-empty/index.js';
|
|
1
2
|
import * as applyEarly from './apply-early/index.js';
|
|
2
3
|
import * as convertFromContinue from './convert-from-continue/index.js';
|
|
3
4
|
import * as convertFromBreak from './convert-from-break/index.js';
|
|
@@ -12,4 +13,5 @@ export const rules = {
|
|
|
12
13
|
'merge-with-next-sibling': mergeWithNextSibling,
|
|
13
14
|
'simplify-boolean': simplifyBoolean,
|
|
14
15
|
'remove-useless': removeUseless,
|
|
16
|
+
'remove-last-empty': removeLastEmpty,
|
|
15
17
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {types} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
isFunction,
|
|
5
|
+
isBlockStatement,
|
|
6
|
+
} = types;
|
|
7
|
+
|
|
8
|
+
export const report = () => `Avoid empty 'return' in function body`;
|
|
9
|
+
|
|
10
|
+
export const match = () => ({
|
|
11
|
+
return: (vars, path) => {
|
|
12
|
+
const {parentPath} = path;
|
|
13
|
+
|
|
14
|
+
if (!isBlockStatement(parentPath))
|
|
15
|
+
return false;
|
|
16
|
+
|
|
17
|
+
const next = path.getNextSibling();
|
|
18
|
+
|
|
19
|
+
if (next.node)
|
|
20
|
+
return false;
|
|
21
|
+
|
|
22
|
+
return isFunction(parentPath.parentPath);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const replace = () => ({
|
|
27
|
+
return: '',
|
|
28
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-return",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin adds ability to transform code related to return",
|
|
@@ -37,21 +37,21 @@
|
|
|
37
37
|
"@putout/plugin-reuse-duplicate-init": "*",
|
|
38
38
|
"@putout/plugin-typescript": "*",
|
|
39
39
|
"@putout/plugin-variables": "*",
|
|
40
|
-
"@putout/test": "^
|
|
41
|
-
"
|
|
42
|
-
"eslint": "^10.0.0-alpha.0",
|
|
40
|
+
"@putout/test": "^15.0.0",
|
|
41
|
+
"eslint": "^10.0.0",
|
|
43
42
|
"eslint-plugin-n": "^17.0.0",
|
|
44
|
-
"eslint-plugin-putout": "^
|
|
45
|
-
"madrun": "^
|
|
43
|
+
"eslint-plugin-putout": "^31.0.0",
|
|
44
|
+
"madrun": "^13.0.0",
|
|
46
45
|
"montag": "^1.2.1",
|
|
47
|
-
"nodemon": "^3.0.1"
|
|
46
|
+
"nodemon": "^3.0.1",
|
|
47
|
+
"superc8": "^12.0.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"putout": ">=
|
|
50
|
+
"putout": ">=42"
|
|
51
51
|
},
|
|
52
52
|
"license": "MIT",
|
|
53
53
|
"engines": {
|
|
54
|
-
"node": ">=
|
|
54
|
+
"node": ">=22"
|
|
55
55
|
},
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|