@putout/plugin-for-of 8.0.0 → 9.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/lib/add-missing-declaration/index.js +32 -7
- package/lib/for-each/index.js +8 -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 -9
|
@@ -1,21 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import {types} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
|
|
3
|
+
const {
|
|
4
|
+
isVariableDeclaration,
|
|
5
|
+
isIdentifier,
|
|
6
|
+
isArrayPattern,
|
|
7
|
+
isObjectPattern,
|
|
8
|
+
} = types;
|
|
5
9
|
|
|
6
|
-
|
|
10
|
+
export const report = () => `Add missing declaration`;
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
export const match = () => ({
|
|
9
13
|
'for (__a of __b) __c': ({__a}, path) => {
|
|
10
14
|
if (isVariableDeclaration(__a))
|
|
11
15
|
return false;
|
|
12
16
|
|
|
13
17
|
const bindings = path.scope.getAllBindings();
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
if (isIdentifier(__a))
|
|
20
|
+
return !bindings[__a.name];
|
|
21
|
+
|
|
22
|
+
if (isArrayPattern(__a)) {
|
|
23
|
+
for (const element of __a.elements) {
|
|
24
|
+
if (!isIdentifier(element) || bindings[element.name])
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (isObjectPattern(__a))
|
|
32
|
+
for (const property of __a.properties) {
|
|
33
|
+
if (property.computed)
|
|
34
|
+
return false;
|
|
35
|
+
|
|
36
|
+
if (!isIdentifier(property.key) || bindings[property.key.name])
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return true;
|
|
16
41
|
},
|
|
17
42
|
});
|
|
18
43
|
|
|
19
|
-
|
|
44
|
+
export const replace = () => ({
|
|
20
45
|
'for (__a of __b) __c': 'for (const __a of __b) __c',
|
|
21
46
|
});
|
package/lib/for-each/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
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
|
-
ContinueStatement,
|
|
11
8
|
isIdentifier,
|
|
9
|
+
continueStatement,
|
|
12
10
|
} = types;
|
|
13
11
|
|
|
14
12
|
const {
|
|
@@ -30,9 +28,9 @@ 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];
|
|
@@ -76,7 +74,7 @@ module.exports.replace = () => ({
|
|
|
76
74
|
},
|
|
77
75
|
});
|
|
78
76
|
|
|
79
|
-
|
|
77
|
+
export const match = () => ({
|
|
80
78
|
'__.forEach(__args)': (vars, path) => {
|
|
81
79
|
const {parentPath} = path;
|
|
82
80
|
|
|
@@ -138,9 +136,9 @@ function fixReturn(path) {
|
|
|
138
136
|
const {argument} = path.node;
|
|
139
137
|
|
|
140
138
|
if (!argument)
|
|
141
|
-
return replaceWith(path,
|
|
139
|
+
return replaceWith(path, continueStatement());
|
|
142
140
|
|
|
143
|
-
replaceWithMultiple(path, [argument,
|
|
141
|
+
replaceWithMultiple(path, [argument, continueStatement()]);
|
|
144
142
|
},
|
|
145
143
|
});
|
|
146
144
|
}
|
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": "9.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,22 +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": "^12.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
|
-
"
|
|
50
|
-
"madrun": "^10.0.0",
|
|
48
|
+
"eslint-plugin-putout": "^26.0.0",
|
|
49
|
+
"madrun": "^11.0.0",
|
|
51
50
|
"montag": "^1.2.1",
|
|
52
51
|
"nodemon": "^3.0.1"
|
|
53
52
|
},
|
|
54
53
|
"peerDependencies": {
|
|
55
|
-
"putout": ">=
|
|
54
|
+
"putout": ">=39"
|
|
56
55
|
},
|
|
57
56
|
"license": "MIT",
|
|
58
57
|
"engines": {
|
|
59
|
-
"node": ">=
|
|
58
|
+
"node": ">=20"
|
|
60
59
|
},
|
|
61
60
|
"publishConfig": {
|
|
62
61
|
"access": "public"
|