@putout/plugin-return 1.0.0 β 1.1.1
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 +4 -4
- package/lib/convert-from-break/index.js +2 -47
- package/lib/convert-from-continue/index.js +2 -41
- package/lib/convert-from.js +60 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -123,7 +123,7 @@ Checkout in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a321ee4d76
|
|
|
123
123
|
function x() {
|
|
124
124
|
if (a)
|
|
125
125
|
break;
|
|
126
|
-
|
|
126
|
+
|
|
127
127
|
return false;
|
|
128
128
|
}
|
|
129
129
|
```
|
|
@@ -151,10 +151,10 @@ function x() {
|
|
|
151
151
|
{
|
|
152
152
|
hello: 'world';
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
return;
|
|
156
156
|
5;
|
|
157
|
-
|
|
157
|
+
|
|
158
158
|
return;
|
|
159
159
|
a ? 2 : 3;
|
|
160
160
|
}
|
|
@@ -208,7 +208,7 @@ Check out in π[**Putout Editor**](https://putout.cloudcmd.io/#/gist/304035b95
|
|
|
208
208
|
function isA(a, b) {
|
|
209
209
|
if (a.length === b.length)
|
|
210
210
|
return true;
|
|
211
|
-
|
|
211
|
+
|
|
212
212
|
return false;
|
|
213
213
|
}
|
|
214
214
|
```
|
|
@@ -1,50 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
const {replaceWith} = operator;
|
|
5
|
-
const {
|
|
6
|
-
isLabeledStatement,
|
|
7
|
-
ReturnStatement,
|
|
8
|
-
} = types;
|
|
3
|
+
const {convertFrom} = require('../convert-from');
|
|
9
4
|
|
|
10
|
-
module.exports
|
|
11
|
-
|
|
12
|
-
module.exports.fix = (path) => {
|
|
13
|
-
replaceWith(path, ReturnStatement());
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
module.exports.traverse = ({push}) => ({
|
|
17
|
-
BreakStatement(path) {
|
|
18
|
-
if (path.node.label) {
|
|
19
|
-
const {name} = path.node.label;
|
|
20
|
-
|
|
21
|
-
const labeledPath = path.find(isLabeledStatement);
|
|
22
|
-
|
|
23
|
-
if (labeledPath && name === labeledPath.node.label.name)
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const upperPath = path.find(isUpperScope);
|
|
28
|
-
|
|
29
|
-
if (upperPath.isLoop())
|
|
30
|
-
return;
|
|
31
|
-
|
|
32
|
-
if (upperPath.isSwitchStatement())
|
|
33
|
-
return;
|
|
34
|
-
|
|
35
|
-
push(path);
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const isUpperScope = (path) => {
|
|
40
|
-
if (path.isLoop())
|
|
41
|
-
return true;
|
|
42
|
-
|
|
43
|
-
if (path.isProgram())
|
|
44
|
-
return true;
|
|
45
|
-
|
|
46
|
-
if (path.isSwitchStatement())
|
|
47
|
-
return true;
|
|
48
|
-
|
|
49
|
-
return path.isFunction();
|
|
50
|
-
};
|
|
5
|
+
module.exports = convertFrom('break');
|
|
@@ -1,44 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
const {
|
|
5
|
-
isLabeledStatement,
|
|
6
|
-
ReturnStatement,
|
|
7
|
-
} = types;
|
|
3
|
+
const {convertFrom} = require('../convert-from');
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
module.exports.report = () => `Use 'return' instead of 'continue'`;
|
|
12
|
-
|
|
13
|
-
module.exports.fix = (path) => {
|
|
14
|
-
replaceWith(path, ReturnStatement());
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
module.exports.traverse = ({push}) => ({
|
|
18
|
-
ContinueStatement(path) {
|
|
19
|
-
if (path.node.label) {
|
|
20
|
-
const {name} = path.node.label;
|
|
21
|
-
const labeledPath = path.find(isLabeledStatement);
|
|
22
|
-
|
|
23
|
-
if (labeledPath && name === labeledPath.node.label.name)
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const upperPath = path.find(isUpperScope);
|
|
28
|
-
|
|
29
|
-
if (upperPath.isLoop())
|
|
30
|
-
return;
|
|
31
|
-
|
|
32
|
-
push(path);
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const isUpperScope = (path) => {
|
|
37
|
-
if (path.isProgram())
|
|
38
|
-
return true;
|
|
39
|
-
|
|
40
|
-
if (path.isLoop())
|
|
41
|
-
return true;
|
|
42
|
-
|
|
43
|
-
return path.isFunction();
|
|
44
|
-
};
|
|
5
|
+
module.exports = convertFrom('continue');
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types, operator} = require('putout');
|
|
4
|
+
const {replaceWith} = operator;
|
|
5
|
+
const {
|
|
6
|
+
isLabeledStatement,
|
|
7
|
+
ReturnStatement,
|
|
8
|
+
} = types;
|
|
9
|
+
|
|
10
|
+
const createReport = (name) => () => `Use 'return' instead of '${name}'`;
|
|
11
|
+
|
|
12
|
+
const fix = (path) => {
|
|
13
|
+
replaceWith(path, ReturnStatement());
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports.convertFrom = (name) => {
|
|
17
|
+
const visitor = name[0].toUpperCase() + name.slice(1) + `Statement`;
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
fix,
|
|
21
|
+
report: createReport(name),
|
|
22
|
+
traverse: createTraverse(visitor),
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const createTraverse = (visitor) => ({push}) => ({
|
|
27
|
+
[visitor](path) {
|
|
28
|
+
if (path.node.label) {
|
|
29
|
+
const {name} = path.node.label;
|
|
30
|
+
|
|
31
|
+
const labeledPath = path.find(isLabeledStatement);
|
|
32
|
+
|
|
33
|
+
if (labeledPath && name === labeledPath.node.label.name)
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const upperPath = path.find(isUpperScope);
|
|
38
|
+
|
|
39
|
+
if (upperPath.isLoop())
|
|
40
|
+
return;
|
|
41
|
+
|
|
42
|
+
if (upperPath.isSwitchStatement())
|
|
43
|
+
return;
|
|
44
|
+
|
|
45
|
+
push(path);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const isUpperScope = (path) => {
|
|
50
|
+
if (path.isLoop())
|
|
51
|
+
return true;
|
|
52
|
+
|
|
53
|
+
if (path.isProgram())
|
|
54
|
+
return true;
|
|
55
|
+
|
|
56
|
+
if (path.isSwitchStatement())
|
|
57
|
+
return true;
|
|
58
|
+
|
|
59
|
+
return path.isFunction();
|
|
60
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-return",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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 related to return",
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"c8": "^10.0.0",
|
|
42
42
|
"eslint": "^9.0.0",
|
|
43
43
|
"eslint-plugin-n": "^17.0.0",
|
|
44
|
-
"eslint-plugin-putout": "^
|
|
44
|
+
"eslint-plugin-putout": "^24.0.0",
|
|
45
45
|
"lerna": "^6.0.1",
|
|
46
46
|
"madrun": "^10.0.0",
|
|
47
47
|
"montag": "^1.2.1",
|
|
48
48
|
"nodemon": "^3.0.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"putout": ">=
|
|
51
|
+
"putout": ">=38"
|
|
52
52
|
},
|
|
53
53
|
"license": "MIT",
|
|
54
54
|
"engines": {
|