@putout/plugin-conditions 4.4.0 → 6.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
CHANGED
|
@@ -19,6 +19,7 @@ npm i @putout/plugin-conditions -D
|
|
|
19
19
|
- ✅ [apply-if](#apply-if);
|
|
20
20
|
- ✅ [convert-comparison-to-boolean](#convert-comparison-to-boolean);
|
|
21
21
|
- ✅ [convert-equal-to-strict-equal](#convert-equal-to-strict-equal);
|
|
22
|
+
- ✅ [convert-arrow-to-condition](#convert-arrow-to-condition);
|
|
22
23
|
- ✅ [evaluate](#evaluate);
|
|
23
24
|
- ✅ [merge-if-statements](#merge-if-statements);
|
|
24
25
|
- ✅ [remove-boolean](#remove-boolean);
|
|
@@ -39,6 +40,7 @@ npm i @putout/plugin-conditions -D
|
|
|
39
40
|
"conditions/add-return": "on",
|
|
40
41
|
"conditions/convert-comparison-to-boolean": "on",
|
|
41
42
|
"conditions/convert-equal-to-strict-equal": "on",
|
|
43
|
+
"conditions/convert-arrow-to-condition": "on",
|
|
42
44
|
"conditions/evaluate": "on",
|
|
43
45
|
"conditions/remove-boolean": "on",
|
|
44
46
|
"conditions/remove-constant": "on",
|
|
@@ -56,7 +58,10 @@ npm i @putout/plugin-conditions -D
|
|
|
56
58
|
>
|
|
57
59
|
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block)
|
|
58
60
|
|
|
59
|
-
Check out in
|
|
61
|
+
Check out in 🐊**Putout Editor**:
|
|
62
|
+
|
|
63
|
+
- [Replacer](https://putout.cloudcmd.io/#/gist/9035db21bae7b6c76d1dc875d4c74828/07edbfd755060ae263949caf08b31aa43609375a);
|
|
64
|
+
- [Traverser](https://putout.cloudcmd.io/#/gist/77f84f100d82707925c73c1784f589f2/25923f46973b99f72378104778499ff75b550d2c);
|
|
60
65
|
|
|
61
66
|
### ❌ Example of incorrect code
|
|
62
67
|
|
|
@@ -163,6 +168,22 @@ if (a)
|
|
|
163
168
|
return false;
|
|
164
169
|
```
|
|
165
170
|
|
|
171
|
+
## convert-arrow-to-condition
|
|
172
|
+
|
|
173
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/4d489393cd08dc771c6324eb0bb2e42f/9e85c4b7b7f2d0f82c660c6db618b31270d3a85e).
|
|
174
|
+
|
|
175
|
+
## ❌ Example of incorrect code
|
|
176
|
+
|
|
177
|
+
```js
|
|
178
|
+
if ((a) => b) {}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## ✅ Example of correct code
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
if (a <= b) {}
|
|
185
|
+
```
|
|
186
|
+
|
|
166
187
|
## convert-comparison-to-boolean
|
|
167
188
|
|
|
168
189
|
> Strict equality compares two values for equality. Neither value is implicitly converted to some other value before being compared. If the values have different types, the values are considered unequal.
|
|
@@ -55,8 +55,13 @@ module.exports.include = () => [
|
|
|
55
55
|
];
|
|
56
56
|
|
|
57
57
|
module.exports.filter = (path) => {
|
|
58
|
+
const {consequent, alternate} = path.node;
|
|
59
|
+
|
|
60
|
+
if (!alternate && !consequent.body?.length)
|
|
61
|
+
return false;
|
|
62
|
+
|
|
58
63
|
if (path === path.parentPath.get('alternate'))
|
|
59
|
-
return;
|
|
64
|
+
return false;
|
|
60
65
|
|
|
61
66
|
const nodes = getAllNodes(path);
|
|
62
67
|
const blocks = [];
|
package/lib/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const removeUselessElse = require('./remove-useless-else');
|
|
|
13
13
|
const simplify = require('./simplify');
|
|
14
14
|
const removeSameValuesCondition = require('./remove-same-values-condition');
|
|
15
15
|
const addReturn = require('./add-return');
|
|
16
|
+
const convertArrowToCondition = require('./convert-arrow-to-condition');
|
|
16
17
|
|
|
17
18
|
module.exports.rules = {
|
|
18
19
|
'apply-comparison-order': applyComparisonOrder,
|
|
@@ -28,4 +29,5 @@ module.exports.rules = {
|
|
|
28
29
|
simplify,
|
|
29
30
|
'remove-same-values-condition': removeSameValuesCondition,
|
|
30
31
|
'add-return': addReturn,
|
|
32
|
+
'convert-arrow-to-condition': convertArrowToCondition,
|
|
31
33
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-conditions",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
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",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"changelog": false,
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git://github.com/coderaiser/putout.git"
|
|
14
|
+
"url": "git+https://github.com/coderaiser/putout.git"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"wisdom": "madrun wisdom",
|
|
@@ -33,22 +33,22 @@
|
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@putout/plugin-for-of": "*",
|
|
36
|
-
"@putout/test": "^
|
|
37
|
-
"c8": "^
|
|
36
|
+
"@putout/test": "^11.0.0",
|
|
37
|
+
"c8": "^10.0.0",
|
|
38
38
|
"eslint": "^9.0.0",
|
|
39
39
|
"eslint-plugin-n": "^17.0.0",
|
|
40
|
-
"eslint-plugin-putout": "^
|
|
40
|
+
"eslint-plugin-putout": "^23.0.0",
|
|
41
41
|
"lerna": "^6.0.1",
|
|
42
42
|
"madrun": "^10.0.0",
|
|
43
43
|
"montag": "^1.2.1",
|
|
44
44
|
"nodemon": "^3.0.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"putout": ">=
|
|
47
|
+
"putout": ">=37"
|
|
48
48
|
},
|
|
49
49
|
"license": "MIT",
|
|
50
50
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
51
|
+
"node": ">=18"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|