@putout/plugin-for-of 4.1.0 → 5.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 +41 -0
- package/lib/add-missing-star/index.js +31 -0
- package/lib/for-each/index.js +3 -0
- package/lib/index.js +2 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -15,11 +15,29 @@
|
|
|
15
15
|
npm i @putout/plugin-for-of
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
## Rules
|
|
19
|
+
|
|
20
|
+
- ✅ [add-missing-star](#add-missing-star);
|
|
21
|
+
- ✅ [for-each](#for-each);
|
|
22
|
+
- ✅ [for-entries](#for-entries);
|
|
23
|
+
- ✅ [for-entries-n](#for-entries-n);
|
|
24
|
+
- ✅ [for-in-negative](#for-in-negative);
|
|
25
|
+
- ✅ [for-in-positive](#for-in-positive);
|
|
26
|
+
- ✅ [for-length](#for-length);
|
|
27
|
+
- ✅ [for-n](#for-n);
|
|
28
|
+
- ✅ [map](#map);
|
|
29
|
+
- ✅ [reduce](#reduce);
|
|
30
|
+
- ✅ [remove-unused-variables](#remove-unused-variables);
|
|
31
|
+
- ✅ [remove-useless](#remove-useless);
|
|
32
|
+
- ✅ [remove-useless-array-from](#remove-useless-array-from);
|
|
33
|
+
- ✅ [remove-useless-variables](#remove-useless-variables);
|
|
34
|
+
|
|
18
35
|
## Configuration
|
|
19
36
|
|
|
20
37
|
```json
|
|
21
38
|
{
|
|
22
39
|
"rules": {
|
|
40
|
+
"for-of/add-missing-star": "on",
|
|
23
41
|
"for-of/map": "on",
|
|
24
42
|
"for-of/for-in": "on",
|
|
25
43
|
"for-of/for-each": "on",
|
|
@@ -35,6 +53,29 @@ npm i @putout/plugin-for-of
|
|
|
35
53
|
}
|
|
36
54
|
```
|
|
37
55
|
|
|
56
|
+
## add-missing-star
|
|
57
|
+
|
|
58
|
+
> The `function*` declaration creates a binding of a new generator function to a given name.
|
|
59
|
+
>
|
|
60
|
+
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*)
|
|
61
|
+
|
|
62
|
+
### ❌ Example of incorrect code
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
function hello() {
|
|
66
|
+
yield;
|
|
67
|
+
'world';
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### ✅ Example of correct code
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
function* hello() {
|
|
75
|
+
yield 'world';
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
38
79
|
## map
|
|
39
80
|
|
|
40
81
|
> The [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) method creates a new array populated with the results of calling a provided function on every element in the calling array.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types, operator} = require('putout');
|
|
4
|
+
const {remove, replaceWith} = operator;
|
|
5
|
+
const {YieldExpression} = types;
|
|
6
|
+
|
|
7
|
+
module.exports.report = () => `Add missing '*' in generator function`;
|
|
8
|
+
|
|
9
|
+
module.exports.fix = (path) => {
|
|
10
|
+
const fnPath = path.getFunctionParent();
|
|
11
|
+
|
|
12
|
+
fnPath.node.generator = true;
|
|
13
|
+
|
|
14
|
+
const next = path.parentPath.getNextSibling();
|
|
15
|
+
const {expression} = next.node;
|
|
16
|
+
|
|
17
|
+
replaceWith(path, YieldExpression(expression));
|
|
18
|
+
remove(next);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports.traverse = ({push}) => ({
|
|
22
|
+
Identifier(path) {
|
|
23
|
+
if (path.node.name !== 'yield')
|
|
24
|
+
return;
|
|
25
|
+
|
|
26
|
+
if (!path.parentPath.isExpressionStatement())
|
|
27
|
+
return;
|
|
28
|
+
|
|
29
|
+
push(path);
|
|
30
|
+
},
|
|
31
|
+
});
|
package/lib/for-each/index.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const addMissingStar = require('./add-missing-star');
|
|
3
4
|
const map = require('./map');
|
|
4
5
|
const forEach = require('./for-each');
|
|
5
6
|
const forN = require('./for-n');
|
|
@@ -15,6 +16,7 @@ const removeUselessArrayFrom = require('./remove-useless-array-from');
|
|
|
15
16
|
const removeUnusedVariables = require('./remove-unused-variables');
|
|
16
17
|
|
|
17
18
|
module.exports.rules = {
|
|
19
|
+
'add-missing-star': addMissingStar,
|
|
18
20
|
map,
|
|
19
21
|
'for-each': forEach,
|
|
20
22
|
'for-n': forN,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-for-of",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.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 apply for...of",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"@putout/plugin-remove-unused-variables": "*",
|
|
41
41
|
"@putout/plugin-remove-useless-arguments": "*",
|
|
42
42
|
"@putout/plugin-remove-useless-continue": "*",
|
|
43
|
-
"@putout/test": "^
|
|
43
|
+
"@putout/test": "^9.0.0",
|
|
44
44
|
"c8": "^9.0.0",
|
|
45
|
-
"eslint": "^9.0.0
|
|
46
|
-
"eslint-plugin-n": "^
|
|
45
|
+
"eslint": "^9.0.0",
|
|
46
|
+
"eslint-plugin-n": "^17.0.0",
|
|
47
47
|
"eslint-plugin-putout": "^22.0.0",
|
|
48
48
|
"lerna": "^6.0.1",
|
|
49
49
|
"madrun": "^10.0.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"nodemon": "^3.0.1"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"putout": ">=
|
|
54
|
+
"putout": ">=35"
|
|
55
55
|
},
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"engines": {
|