@putout/plugin-conditions 1.0.2 → 1.0.3
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 +3 -6
- package/lib/apply-if/index.js +6 -2
- package/lib/convert-comparison-to-boolean/index.js +5 -1
- package/lib/convert-equal-to-strict-equal/index.js +0 -1
- package/lib/evaluate/index.js +0 -1
- package/lib/index.js +0 -1
- package/lib/remove-boolean/index.js +2 -7
- package/lib/remove-constant/index.js +3 -4
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -101,15 +101,13 @@ const t = false;
|
|
|
101
101
|
### ❌ Example of incorrect code
|
|
102
102
|
|
|
103
103
|
```js
|
|
104
|
-
if (a == b) {
|
|
105
|
-
}
|
|
104
|
+
if (a == b) {}
|
|
106
105
|
```
|
|
107
106
|
|
|
108
107
|
### ✅ Example of correct code
|
|
109
108
|
|
|
110
109
|
```js
|
|
111
|
-
if (a === b) {
|
|
112
|
-
}
|
|
110
|
+
if (a === b) {}
|
|
113
111
|
```
|
|
114
112
|
|
|
115
113
|
## evaluate
|
|
@@ -186,8 +184,7 @@ if (zone?.tooltipCallback) {
|
|
|
186
184
|
}
|
|
187
185
|
|
|
188
186
|
if (a)
|
|
189
|
-
alert('hello');
|
|
190
|
-
else
|
|
187
|
+
alert('hello');else
|
|
191
188
|
alert('hello');
|
|
192
189
|
```
|
|
193
190
|
|
package/lib/apply-if/index.js
CHANGED
|
@@ -10,10 +10,14 @@ module.exports.filter = (path) => {
|
|
|
10
10
|
if (!nextPath.node)
|
|
11
11
|
return false;
|
|
12
12
|
|
|
13
|
-
return path
|
|
13
|
+
return path
|
|
14
|
+
.get('consequent')
|
|
15
|
+
.isEmptyStatement();
|
|
14
16
|
};
|
|
15
17
|
|
|
16
|
-
module.exports.include = () => [
|
|
18
|
+
module.exports.include = () => [
|
|
19
|
+
'IfStatement',
|
|
20
|
+
];
|
|
17
21
|
|
|
18
22
|
module.exports.fix = (path) => {
|
|
19
23
|
const nextPath = path.getNextSibling();
|
package/lib/evaluate/index.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -5,19 +5,14 @@ module.exports.report = () => 'Avoid boolean in assertions';
|
|
|
5
5
|
module.exports.replace = () => ({
|
|
6
6
|
'return __a === true': 'return Boolean(__a)',
|
|
7
7
|
'return __a == true': 'return Boolean(__a)',
|
|
8
|
-
|
|
9
|
-
'const __a = __b
|
|
10
|
-
'const __a = __b == true': 'const __a = __b == Boolean(__a)',
|
|
11
|
-
|
|
8
|
+
'const __a = __b === true': 'const __a = __b',
|
|
9
|
+
'const __a = __b == true': 'const __a = __b',
|
|
12
10
|
'__a = __b === true': '__a = __b === Boolean(__a)',
|
|
13
11
|
'__a = __b == true': '__a = __b == Boolean(__a)',
|
|
14
|
-
|
|
15
12
|
'__a === true': '__a',
|
|
16
13
|
'__a === false': '!__a',
|
|
17
14
|
'__a == true': '__a',
|
|
18
15
|
'__a == false': '!__a',
|
|
19
|
-
|
|
20
16
|
'__a !== true': '!__a',
|
|
21
17
|
'__a != true': '!__a',
|
|
22
18
|
});
|
|
23
|
-
|
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
replaceWithMultiple,
|
|
13
13
|
remove,
|
|
14
14
|
} = operator;
|
|
15
|
+
|
|
15
16
|
const {isIdentifier} = types;
|
|
16
17
|
|
|
17
18
|
module.exports.report = () => 'Avoid constant conditions';
|
|
@@ -22,9 +23,7 @@ module.exports.fix = ({path, result}) => {
|
|
|
22
23
|
consequent,
|
|
23
24
|
} = path.node;
|
|
24
25
|
|
|
25
|
-
const {
|
|
26
|
-
body = [consequent],
|
|
27
|
-
} = consequent;
|
|
26
|
+
const {body = [consequent]} = consequent;
|
|
28
27
|
|
|
29
28
|
if (result)
|
|
30
29
|
return replaceWithMultiple(path, body);
|
|
@@ -38,6 +37,7 @@ module.exports.fix = ({path, result}) => {
|
|
|
38
37
|
module.exports.traverse = ({push, generate}) => ({
|
|
39
38
|
IfStatement(path) {
|
|
40
39
|
const testPath = path.get('test');
|
|
40
|
+
|
|
41
41
|
const {
|
|
42
42
|
left,
|
|
43
43
|
right,
|
|
@@ -78,4 +78,3 @@ function containsIdentifiers(testPath) {
|
|
|
78
78
|
|
|
79
79
|
return is;
|
|
80
80
|
}
|
|
81
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-conditions",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout plugin adds support of conditions transformations",
|
|
@@ -32,13 +32,12 @@
|
|
|
32
32
|
"conditions"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@putout/plugin-
|
|
36
|
-
"@putout/plugin-remove-useless-variables": "^7.3.0",
|
|
35
|
+
"@putout/plugin-for-of": "*",
|
|
37
36
|
"@putout/test": "^6.0.0",
|
|
38
37
|
"c8": "^7.5.0",
|
|
39
38
|
"eslint": "^8.0.1",
|
|
40
39
|
"eslint-plugin-n": "^15.2.4",
|
|
41
|
-
"eslint-plugin-putout": "^
|
|
40
|
+
"eslint-plugin-putout": "^17.0.0",
|
|
42
41
|
"lerna": "^6.0.1",
|
|
43
42
|
"madrun": "^9.0.0",
|
|
44
43
|
"montag": "^1.2.1",
|