@putout/plugin-conditions 6.0.0 → 6.2.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 +18 -0
- package/lib/apply-consistent-blocks/index.js +18 -7
- package/lib/index.js +2 -0
- package/lib/reverse-condition/index.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ npm i @putout/plugin-conditions -D
|
|
|
22
22
|
- ✅ [convert-arrow-to-condition](#convert-arrow-to-condition);
|
|
23
23
|
- ✅ [evaluate](#evaluate);
|
|
24
24
|
- ✅ [merge-if-statements](#merge-if-statements);
|
|
25
|
+
- ✅ [reverse](#reverse);
|
|
25
26
|
- ✅ [remove-boolean](#remove-boolean);
|
|
26
27
|
- ✅ [remove-constant](#remove-constant);
|
|
27
28
|
- ✅ [remove-same-values-condition](hremove-same-values-condition);
|
|
@@ -42,6 +43,7 @@ npm i @putout/plugin-conditions -D
|
|
|
42
43
|
"conditions/convert-equal-to-strict-equal": "on",
|
|
43
44
|
"conditions/convert-arrow-to-condition": "on",
|
|
44
45
|
"conditions/evaluate": "on",
|
|
46
|
+
"conditions/reverse": "on",
|
|
45
47
|
"conditions/remove-boolean": "on",
|
|
46
48
|
"conditions/remove-constant": "on",
|
|
47
49
|
"conditions/remove-zero": "on",
|
|
@@ -245,6 +247,22 @@ const c = a;
|
|
|
245
247
|
console.log(a);
|
|
246
248
|
```
|
|
247
249
|
|
|
250
|
+
## reverse
|
|
251
|
+
|
|
252
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/fabfc16a5a5d1002c721fc2dfc31474b/8d1de98533ef439e56e8784f54a34c3928a074fa).
|
|
253
|
+
|
|
254
|
+
### ❌ Example of incorrect code
|
|
255
|
+
|
|
256
|
+
```js
|
|
257
|
+
const check = (references) => !(references > 3);
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### ✅ Example of correct code
|
|
261
|
+
|
|
262
|
+
```js
|
|
263
|
+
const check = (references) => references <= 3;
|
|
264
|
+
```
|
|
265
|
+
|
|
248
266
|
## remove-boolean
|
|
249
267
|
|
|
250
268
|
### ❌ Example of incorrect code
|
|
@@ -5,6 +5,8 @@ const {replaceWith} = operator;
|
|
|
5
5
|
const {
|
|
6
6
|
isBlockStatement,
|
|
7
7
|
BlockStatement,
|
|
8
|
+
isExpressionStatement,
|
|
9
|
+
isIfStatement,
|
|
8
10
|
} = types;
|
|
9
11
|
|
|
10
12
|
module.exports.report = () => `Use consistent blocks`;
|
|
@@ -63,11 +65,20 @@ module.exports.filter = (path) => {
|
|
|
63
65
|
if (path === path.parentPath.get('alternate'))
|
|
64
66
|
return false;
|
|
65
67
|
|
|
66
|
-
const
|
|
68
|
+
const paths = getAllNodes(path);
|
|
67
69
|
const blocks = [];
|
|
68
70
|
|
|
69
|
-
for (const
|
|
70
|
-
const is = isBlockStatement(
|
|
71
|
+
for (const path of paths) {
|
|
72
|
+
const is = isBlockStatement(path);
|
|
73
|
+
const {body} = path.node;
|
|
74
|
+
|
|
75
|
+
if (is && body.length === 1) {
|
|
76
|
+
const [first] = body;
|
|
77
|
+
|
|
78
|
+
if (!isExpressionStatement(first) && !isIfStatement(first))
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
71
82
|
blocks.push(is);
|
|
72
83
|
}
|
|
73
84
|
|
|
@@ -78,8 +89,8 @@ module.exports.filter = (path) => {
|
|
|
78
89
|
|
|
79
90
|
const couple = [];
|
|
80
91
|
|
|
81
|
-
for (const
|
|
82
|
-
const is = isBlockStatement(
|
|
92
|
+
for (const path of paths) {
|
|
93
|
+
const is = isBlockStatement(path) && path.node.body.length > 1;
|
|
83
94
|
couple.push(is);
|
|
84
95
|
}
|
|
85
96
|
|
|
@@ -88,10 +99,10 @@ module.exports.filter = (path) => {
|
|
|
88
99
|
if (!coupleCount)
|
|
89
100
|
return true;
|
|
90
101
|
|
|
91
|
-
if (coupleCount ===
|
|
102
|
+
if (coupleCount === paths.length)
|
|
92
103
|
return false;
|
|
93
104
|
|
|
94
|
-
return !(count !== 1 && count ===
|
|
105
|
+
return !(count !== 1 && count === paths.length);
|
|
95
106
|
};
|
|
96
107
|
|
|
97
108
|
function getAllNodes(path, nodes = []) {
|
package/lib/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const simplify = require('./simplify');
|
|
|
14
14
|
const removeSameValuesCondition = require('./remove-same-values-condition');
|
|
15
15
|
const addReturn = require('./add-return');
|
|
16
16
|
const convertArrowToCondition = require('./convert-arrow-to-condition');
|
|
17
|
+
const reverseCondition = require('./reverse-condition');
|
|
17
18
|
|
|
18
19
|
module.exports.rules = {
|
|
19
20
|
'apply-comparison-order': applyComparisonOrder,
|
|
@@ -30,4 +31,5 @@ module.exports.rules = {
|
|
|
30
31
|
'remove-same-values-condition': removeSameValuesCondition,
|
|
31
32
|
'add-return': addReturn,
|
|
32
33
|
'convert-arrow-to-condition': convertArrowToCondition,
|
|
34
|
+
'reverse-condition': reverseCondition,
|
|
33
35
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-conditions",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.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",
|