@putout/plugin-for-of 8.1.0 β 10.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 +1 -1
- package/lib/add-missing-declaration/index.js +4 -5
- package/lib/for-each/index.js +21 -10
- package/lib/for-entries/index.js +5 -7
- package/lib/for-entries-n/index.js +5 -7
- package/lib/for-in-negative/index.js +4 -6
- package/lib/for-in-positive/index.js +4 -6
- package/lib/for-length/index.js +5 -7
- package/lib/for-n/index.js +5 -7
- package/lib/index.js +16 -18
- package/lib/map/index.js +4 -5
- package/lib/reduce/index.js +4 -5
- package/lib/remove-unused-variables/index.js +4 -6
- package/lib/remove-useless/index.js +4 -6
- package/lib/remove-useless-array-from/index.js +2 -4
- package/lib/remove-useless-variables/index.js +4 -6
- package/lib/to-for-n/index.js +3 -5
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ npm i @putout/plugin-for-of
|
|
|
61
61
|
>
|
|
62
62
|
> (c) MDN
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
Checkout in π[**Putout Editor**](https://putout.vercel.app/#/gist/68d114f01384084cc3bec0a5d75f2dfa/0bb5201d36ed27f74728921aca95a04efa35c82d).
|
|
65
65
|
|
|
66
66
|
### β Example of incorrect code
|
|
67
67
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {types} = require('putout');
|
|
4
3
|
const {
|
|
5
4
|
isVariableDeclaration,
|
|
6
5
|
isIdentifier,
|
|
@@ -8,9 +7,9 @@ const {
|
|
|
8
7
|
isObjectPattern,
|
|
9
8
|
} = types;
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
export const report = () => `Add missing declaration`;
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
export const match = () => ({
|
|
14
13
|
'for (__a of __b) __c': ({__a}, path) => {
|
|
15
14
|
if (isVariableDeclaration(__a))
|
|
16
15
|
return false;
|
|
@@ -42,6 +41,6 @@ module.exports.match = () => ({
|
|
|
42
41
|
},
|
|
43
42
|
});
|
|
44
43
|
|
|
45
|
-
|
|
44
|
+
export const replace = () => ({
|
|
46
45
|
'for (__a of __b) __c': 'for (const __a of __b) __c',
|
|
47
46
|
});
|
package/lib/for-each/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
template,
|
|
5
3
|
operator,
|
|
6
4
|
types,
|
|
7
|
-
}
|
|
5
|
+
} from 'putout';
|
|
8
6
|
|
|
9
7
|
const {
|
|
10
8
|
isIdentifier,
|
|
@@ -30,19 +28,22 @@ const forOfEntriesTemplate = template(`
|
|
|
30
28
|
const {keys} = Object;
|
|
31
29
|
const isRoot = (path) => path.isFunction() || path.isProgram();
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
export const report = () => `Use 'for-of' instead of 'forEach()'`;
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
export const replace = () => ({
|
|
36
34
|
'__.forEach.call(__a, (__b) => __body)': 'for (const __b of __a) __body',
|
|
37
35
|
'__.forEach(__args)': (vars, path) => {
|
|
38
36
|
const {params, body} = path.node.arguments[0];
|
|
39
|
-
|
|
40
37
|
const item = getItem(params);
|
|
41
38
|
|
|
42
39
|
delete item.typeAnnotation;
|
|
43
40
|
|
|
44
41
|
const {length} = params;
|
|
45
42
|
|
|
43
|
+
for (const param of params) {
|
|
44
|
+
delete param.typeAnnotation;
|
|
45
|
+
}
|
|
46
|
+
|
|
46
47
|
const thisPassed = isIdentifier(params[0], {
|
|
47
48
|
name: 'this',
|
|
48
49
|
});
|
|
@@ -76,7 +77,7 @@ module.exports.replace = () => ({
|
|
|
76
77
|
},
|
|
77
78
|
});
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
export const match = () => ({
|
|
80
81
|
'__.forEach(__args)': (vars, path) => {
|
|
81
82
|
const {parentPath} = path;
|
|
82
83
|
|
|
@@ -106,8 +107,7 @@ module.exports.match = () => ({
|
|
|
106
107
|
if (path.node.arguments.length === 2 && !path.get('arguments.1').isThisExpression())
|
|
107
108
|
return false;
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
if (params.length >= 3 && params[0].isIdentifier({name: 'this'}))
|
|
110
|
+
if (isIndexWithThis(params))
|
|
111
111
|
return false;
|
|
112
112
|
|
|
113
113
|
const [paramPath] = params;
|
|
@@ -200,3 +200,14 @@ function isForBeforeFnUp(path) {
|
|
|
200
200
|
|
|
201
201
|
return true;
|
|
202
202
|
}
|
|
203
|
+
|
|
204
|
+
function isIndexWithThis(params) {
|
|
205
|
+
if (params.length < 3)
|
|
206
|
+
return false;
|
|
207
|
+
|
|
208
|
+
const [first] = params;
|
|
209
|
+
|
|
210
|
+
return first.isIdentifier({
|
|
211
|
+
name: 'this',
|
|
212
|
+
});
|
|
213
|
+
}
|
package/lib/for-entries/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
operator,
|
|
5
3
|
types,
|
|
6
4
|
template,
|
|
7
|
-
}
|
|
5
|
+
} from 'putout';
|
|
8
6
|
|
|
9
7
|
const {
|
|
10
8
|
compare,
|
|
@@ -13,14 +11,14 @@ const {
|
|
|
13
11
|
|
|
14
12
|
const {isBlockStatement} = types;
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
export const report = () => `Use 'for...of' instead of 'for'`;
|
|
17
15
|
|
|
18
16
|
const forLoop = 'for (let __i = 0; __i < __e.length; __i++) __c';
|
|
19
17
|
const getForOfLoop = template(`for (const [INDEX, ITEM] of ITEMS.entries()) BODY`);
|
|
20
18
|
const assignIterable = (__i) => `const __a = __b[${__i.name}]`;
|
|
21
19
|
const assignIterableWithName = (__i, __e) => `const __a = ${__e.name}[${__i.name}]`;
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
export const filter = (path) => {
|
|
24
22
|
const {node} = path;
|
|
25
23
|
const {body} = node;
|
|
26
24
|
|
|
@@ -43,7 +41,7 @@ module.exports.filter = (path) => {
|
|
|
43
41
|
return compare(first, assignIterableWithName(__i, __e));
|
|
44
42
|
};
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
export const replace = () => ({
|
|
47
45
|
[forLoop]: ({__c, __i}) => {
|
|
48
46
|
const [node] = __c.body;
|
|
49
47
|
const {__a, __b} = getTemplateValues(node, assignIterable(__i));
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
operator,
|
|
5
3
|
template,
|
|
6
4
|
types,
|
|
7
|
-
}
|
|
5
|
+
} from 'putout';
|
|
8
6
|
|
|
9
7
|
const {
|
|
10
8
|
compare,
|
|
@@ -13,14 +11,14 @@ const {
|
|
|
13
11
|
|
|
14
12
|
const {isBlockStatement} = types;
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
export const report = () => `Use 'for...of' instead of 'for'`;
|
|
17
15
|
|
|
18
16
|
const forLoopToN = 'for (let __i = 0; __i < __n; __i++) __c';
|
|
19
17
|
const getForOfLoop = template(`for (const [INDEX, LEFT] of RIGHT.entries()) BODY`);
|
|
20
18
|
const assignIterable = (__i) => `const __a = __b[${__i.name}]`;
|
|
21
19
|
const assignN = (__n) => `const ${__n.name} = __e.length`;
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
export const filter = (path) => {
|
|
24
22
|
const {node} = path;
|
|
25
23
|
const prevPath = path.getPrevSibling();
|
|
26
24
|
|
|
@@ -57,7 +55,7 @@ module.exports.filter = (path) => {
|
|
|
57
55
|
return references > 3;
|
|
58
56
|
};
|
|
59
57
|
|
|
60
|
-
|
|
58
|
+
export const replace = () => ({
|
|
61
59
|
[forLoopToN]: ({__c, __i}) => {
|
|
62
60
|
const [node] = __c.body;
|
|
63
61
|
const {__a, __b} = getTemplateValues(node, assignIterable(__i));
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {generate, operator} = require('putout');
|
|
1
|
+
import {generate, operator} from 'putout';
|
|
4
2
|
|
|
5
3
|
const {
|
|
6
4
|
contains,
|
|
7
5
|
getTemplateValues,
|
|
8
6
|
} = operator;
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
export const report = () => `for-of should be used instead of for-in`;
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
export const match = () => ({
|
|
13
11
|
'for (__a in __b) __body': ({__a, __b, __body}) => {
|
|
14
12
|
const declaration = getTemplateValues(__a, 'var __a');
|
|
15
13
|
|
|
@@ -22,7 +20,7 @@ module.exports.match = () => ({
|
|
|
22
20
|
},
|
|
23
21
|
});
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
export const replace = () => ({
|
|
26
24
|
'for (__a in __b) __body': ({__b, __body}) => {
|
|
27
25
|
const [first] = __body.body;
|
|
28
26
|
const condition = getTemplateValues(first, 'if (!__b.hasOwnProperty(__a)) __c');
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {generate, operator} = require('putout');
|
|
1
|
+
import {generate, operator} from 'putout';
|
|
4
2
|
|
|
5
3
|
const {
|
|
6
4
|
contains,
|
|
7
5
|
getTemplateValues,
|
|
8
6
|
} = operator;
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
export const report = () => `for-of should be used instead of for-in`;
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
export const match = () => ({
|
|
13
11
|
'for (__a in __b) __body': ({__a, __b, __body}) => {
|
|
14
12
|
const declaration = getTemplateValues(__a, 'var __a');
|
|
15
13
|
|
|
@@ -22,7 +20,7 @@ module.exports.match = () => ({
|
|
|
22
20
|
},
|
|
23
21
|
});
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
export const replace = () => ({
|
|
26
24
|
'for (__a in __b) __body': ({__b, __body}) => {
|
|
27
25
|
const [first] = __body.body;
|
|
28
26
|
const condition = getTemplateValues(first, 'if (__b.hasOwnProperty(__a)) __body');
|
package/lib/for-length/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
operator,
|
|
5
3
|
types,
|
|
6
4
|
template,
|
|
7
|
-
}
|
|
5
|
+
} from 'putout';
|
|
8
6
|
|
|
9
7
|
const {
|
|
10
8
|
compare,
|
|
@@ -13,14 +11,14 @@ const {
|
|
|
13
11
|
|
|
14
12
|
const {isBlockStatement} = types;
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
export const report = () => `Use 'for...of' instead of 'for'`;
|
|
17
15
|
|
|
18
16
|
const forLoop = 'for (let __i = 0; __i < __e.length; __i++) __c';
|
|
19
17
|
const getForOfLoop = template(`for (const LEFT of RIGHT) BODY`);
|
|
20
18
|
const assignIterable = (__i) => `const __a = __b[${__i.name}]`;
|
|
21
19
|
const assignIterableWithName = (__i, __e) => `const __a = ${__e.name}[${__i.name}]`;
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
export const filter = (path) => {
|
|
24
22
|
const {node} = path;
|
|
25
23
|
const {body} = node;
|
|
26
24
|
|
|
@@ -37,7 +35,7 @@ module.exports.filter = (path) => {
|
|
|
37
35
|
return compare(first, assignIterableWithName(__i, __e));
|
|
38
36
|
};
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
export const replace = () => ({
|
|
41
39
|
[forLoop]: ({__c, __i}) => {
|
|
42
40
|
const [node] = __c.body;
|
|
43
41
|
const {__a, __b} = getTemplateValues(node, assignIterable(__i));
|
package/lib/for-n/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
1
|
+
import {
|
|
4
2
|
operator,
|
|
5
3
|
template,
|
|
6
4
|
types,
|
|
7
|
-
}
|
|
5
|
+
} from 'putout';
|
|
8
6
|
|
|
9
7
|
const {
|
|
10
8
|
compare,
|
|
@@ -13,14 +11,14 @@ const {
|
|
|
13
11
|
|
|
14
12
|
const {isBlockStatement} = types;
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
export const report = () => `Use 'for...of' instead of 'for'`;
|
|
17
15
|
|
|
18
16
|
const forLoopToN = 'for (let __i = 0; __i < __n; __i++) __c';
|
|
19
17
|
const getForOfLoop = template(`for (const LEFT of RIGHT) BODY`);
|
|
20
18
|
const assignIterable = (__i) => `const __a = __b[${__i.name}]`;
|
|
21
19
|
const assignN = (__n) => `const ${__n.name} = __e.length`;
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
export const filter = (path) => {
|
|
24
22
|
const {node} = path;
|
|
25
23
|
const prevPath = path.getPrevSibling();
|
|
26
24
|
|
|
@@ -46,7 +44,7 @@ module.exports.filter = (path) => {
|
|
|
46
44
|
return references <= 3;
|
|
47
45
|
};
|
|
48
46
|
|
|
49
|
-
|
|
47
|
+
export const replace = () => ({
|
|
50
48
|
[forLoopToN]: ({__c, __i}) => {
|
|
51
49
|
const [node] = __c.body;
|
|
52
50
|
const {__a, __b} = getTemplateValues(node, assignIterable(__i));
|
package/lib/index.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import * as map from './map/index.js';
|
|
2
|
+
import * as forEach from './for-each/index.js';
|
|
3
|
+
import * as forN from './for-n/index.js';
|
|
4
|
+
import * as forLength from './for-length/index.js';
|
|
5
|
+
import * as forEntries from './for-entries/index.js';
|
|
6
|
+
import * as forEntriesN from './for-entries-n/index.js';
|
|
7
|
+
import * as forInNegative from './for-in-negative/index.js';
|
|
8
|
+
import * as forInPositive from './for-in-positive/index.js';
|
|
9
|
+
import * as reduce from './reduce/index.js';
|
|
10
|
+
import * as removeUseless from './remove-useless/index.js';
|
|
11
|
+
import * as removeUselessVariables from './remove-useless-variables/index.js';
|
|
12
|
+
import * as removeUselessArrayFrom from './remove-useless-array-from/index.js';
|
|
13
|
+
import * as removeUnusedVariables from './remove-unused-variables/index.js';
|
|
14
|
+
import * as addMissingDeclaration from './add-missing-declaration/index.js';
|
|
15
|
+
import * as toForN from './to-for-n/index.js';
|
|
2
16
|
|
|
3
|
-
const
|
|
4
|
-
const forEach = require('./for-each');
|
|
5
|
-
const forN = require('./for-n');
|
|
6
|
-
const forLength = require('./for-length');
|
|
7
|
-
const forEntries = require('./for-entries');
|
|
8
|
-
const forEntriesN = require('./for-entries-n');
|
|
9
|
-
const forInNegative = require('./for-in-negative');
|
|
10
|
-
const forInPositive = require('./for-in-positive');
|
|
11
|
-
const reduce = require('./reduce');
|
|
12
|
-
const removeUseless = require('./remove-useless');
|
|
13
|
-
const removeUselessVariables = require('./remove-useless-variables');
|
|
14
|
-
const removeUselessArrayFrom = require('./remove-useless-array-from');
|
|
15
|
-
const removeUnusedVariables = require('./remove-unused-variables');
|
|
16
|
-
const addMissingDeclaration = require('./add-missing-declaration');
|
|
17
|
-
const toForN = require('./to-for-n');
|
|
18
|
-
|
|
19
|
-
module.exports.rules = {
|
|
17
|
+
export const rules = {
|
|
20
18
|
map,
|
|
21
19
|
'for-each': forEach,
|
|
22
20
|
'for-n': forN,
|
package/lib/map/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {types} = require('putout');
|
|
4
3
|
const {
|
|
5
4
|
isReturnStatement,
|
|
6
5
|
isBlockStatement,
|
|
@@ -9,9 +8,9 @@ const {
|
|
|
9
8
|
|
|
10
9
|
const tail = (body) => body.at(-1);
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
export const report = () => `Use 'for...of' instead of map when 'return' absent`;
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
export const match = () => ({
|
|
15
14
|
'__a.map((__b) => __c)': ({__c}, path) => {
|
|
16
15
|
if (!path.parentPath.isExpressionStatement())
|
|
17
16
|
return false;
|
|
@@ -28,7 +27,7 @@ module.exports.match = () => ({
|
|
|
28
27
|
},
|
|
29
28
|
});
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
export const replace = () => ({
|
|
32
31
|
'__a.map((__b) => __c)': (vars, path) => {
|
|
33
32
|
const a = path.get('callee.object');
|
|
34
33
|
const b = path.get('arguments.0.params.0');
|
package/lib/reduce/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {types} = require('putout');
|
|
4
3
|
const {
|
|
5
4
|
isBlockStatement,
|
|
6
5
|
isArrayExpression,
|
|
7
6
|
isCallExpression,
|
|
8
7
|
} = types;
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
export const report = () => `Use 'for...of' instead of '.reduce()'`;
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
export const match = () => ({
|
|
13
12
|
'const __a = __b.reduce((__c, __d) => __e)': ({__b, __e}) => {
|
|
14
13
|
if (isArrayExpression(__b))
|
|
15
14
|
return false;
|
|
@@ -28,7 +27,7 @@ module.exports.match = () => ({
|
|
|
28
27
|
'const __a = __b.reduce((__c, __d) => __e, __f)': ({__e}) => !isBlockStatement(__e),
|
|
29
28
|
});
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
export const replace = () => ({
|
|
32
31
|
'const __a = __b.reduce((__c, __d) => __e)': ({__a, __d}, path) => {
|
|
33
32
|
path.__putout_for_of_reduce = true;
|
|
34
33
|
rename(path, __d, __a);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types, operator} = require('putout');
|
|
1
|
+
import {types, operator} from 'putout';
|
|
4
2
|
|
|
5
3
|
const {
|
|
6
4
|
isIdentifier,
|
|
@@ -10,19 +8,19 @@ const {
|
|
|
10
8
|
const {remove} = operator;
|
|
11
9
|
const getValue = ({value}) => value;
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
export const report = (path) => {
|
|
14
12
|
const variables = getVariables(path);
|
|
15
13
|
const names = getNames(variables);
|
|
16
14
|
|
|
17
15
|
return `'${names.join(', ')}' inside 'for...of' loop defined but never used`;
|
|
18
16
|
};
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
export const match = () => ({
|
|
21
19
|
'for (const __array of __b) __c': matchForOf,
|
|
22
20
|
'for (const __object of __b) __c': matchForOf,
|
|
23
21
|
});
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
export const replace = () => ({
|
|
26
24
|
'for (const __array of __b) __c': replaceForOf,
|
|
27
25
|
'for (const __object of __b) __c': replaceForOf,
|
|
28
26
|
});
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types, operator} = require('putout');
|
|
1
|
+
import {types, operator} from 'putout';
|
|
4
2
|
|
|
5
3
|
const {isIdentifier} = types;
|
|
6
4
|
const {replaceWith} = operator;
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
export const report = () => `Avoid useless for-of`;
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
export const match = () => ({
|
|
11
9
|
'for (const __identifier__a of __identifier__b) __c': ({__identifier__a}, path) => {
|
|
12
10
|
const {name} = __identifier__a;
|
|
13
11
|
const {references} = path.scope.bindings[name];
|
|
@@ -28,7 +26,7 @@ module.exports.match = () => ({
|
|
|
28
26
|
},
|
|
29
27
|
});
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
export const replace = () => ({
|
|
32
30
|
'for (const __identifier__a of __identifier__b) __c': '__c',
|
|
33
31
|
'for (const __a of __array) __c': ({__a, __c, __array}, path) => {
|
|
34
32
|
const {elements} = __array;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
'
|
|
1
|
+
export const report = () => `'Array.from()' has no sense inside 'for...of'`;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports.replace = () => ({
|
|
3
|
+
export const replace = () => ({
|
|
6
4
|
'for (const __a of Array.from(__b)) __c': 'for (const __a of __b) __c',
|
|
7
5
|
});
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {types, operator} = require('putout');
|
|
1
|
+
import {types, operator} from 'putout';
|
|
4
2
|
|
|
5
3
|
const {replaceWith, remove} = operator;
|
|
6
4
|
const {
|
|
@@ -11,14 +9,14 @@ const {
|
|
|
11
9
|
const isToManyProperties = (a, {maxProperties}) => a.isObjectPattern() && a.node.properties.length > maxProperties;
|
|
12
10
|
const isAssignment = (a) => isAssignmentPattern(a.value);
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
export const report = () => `Use destructuring in head of 'for...of'`;
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
export const fix = ({path, varPath}) => {
|
|
17
15
|
replaceWith(varPath, path.node.id);
|
|
18
16
|
remove(path);
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
export const traverse = ({push, options}) => ({
|
|
22
20
|
'for (const __ of __) __'(path) {
|
|
23
21
|
const leftPath = path.get('left');
|
|
24
22
|
const varPath = leftPath.get('declarations.0.id');
|
package/lib/to-for-n/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
'
|
|
1
|
+
export const report = () => `Use 'for' instead of 'for...of' with '.entries()' when change index`;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports.match = () => ({
|
|
3
|
+
export const match = () => ({
|
|
6
4
|
'for (let [__a, __b] of __c.entries())__body': ({__a}, path) => {
|
|
7
5
|
const binding = path.scope.bindings[__a.name];
|
|
8
6
|
return binding.constantViolations.length;
|
|
9
7
|
},
|
|
10
8
|
});
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
export const replace = () => ({
|
|
13
11
|
'for (let [__a, __b] of __c.entries())__body': (vars, path) => {
|
|
14
12
|
const {n} = path.parentPath.scope.bindings;
|
|
15
13
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-for-of",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "πPutout plugin adds ability to apply for...of",
|
|
7
7
|
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-for-of#readme",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"for-of"
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@putout/eslint-flat": "^
|
|
34
|
+
"@putout/eslint-flat": "^3.0.0",
|
|
35
35
|
"@putout/plugin-conditions": "*",
|
|
36
36
|
"@putout/plugin-convert-const-to-let": "*",
|
|
37
37
|
"@putout/plugin-remove-console": "*",
|
|
@@ -41,21 +41,21 @@
|
|
|
41
41
|
"@putout/plugin-remove-unused-variables": "*",
|
|
42
42
|
"@putout/plugin-remove-useless-arguments": "*",
|
|
43
43
|
"@putout/plugin-remove-useless-continue": "*",
|
|
44
|
-
"@putout/test": "^
|
|
44
|
+
"@putout/test": "^14.0.0",
|
|
45
45
|
"c8": "^10.0.0",
|
|
46
46
|
"eslint": "^9.0.0",
|
|
47
47
|
"eslint-plugin-n": "^17.0.0",
|
|
48
|
-
"eslint-plugin-putout": "^
|
|
49
|
-
"madrun": "^
|
|
48
|
+
"eslint-plugin-putout": "^28.0.0",
|
|
49
|
+
"madrun": "^11.0.0",
|
|
50
50
|
"montag": "^1.2.1",
|
|
51
51
|
"nodemon": "^3.0.1"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"putout": ">=
|
|
54
|
+
"putout": ">=40"
|
|
55
55
|
},
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"engines": {
|
|
58
|
-
"node": ">=
|
|
58
|
+
"node": ">=20"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|