@putout/plugin-conditions 8.3.0 → 8.5.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 +13 -10
- package/lib/apply-equal/index.js +5 -0
- package/lib/index.js +3 -1
- package/lib/remove-zero/index.js +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ npm i @putout/plugin-conditions -D
|
|
|
16
16
|
- ✅ [add-return](#add-return);
|
|
17
17
|
- ✅ [apply-comparison-order](#apply-comparison-order);
|
|
18
18
|
- ✅ [apply-consistent-blocks](#apply-consistent-blocks);
|
|
19
|
+
- ✅ [apply-equal](#apply-equal);
|
|
19
20
|
- ✅ [apply-if](#apply-if);
|
|
20
21
|
- ✅ [convert-comparison-to-boolean](#convert-comparison-to-boolean);
|
|
21
22
|
- ✅ [convert-equal-to-strict-equal](#convert-equal-to-strict-equal);
|
|
@@ -40,6 +41,7 @@ npm i @putout/plugin-conditions -D
|
|
|
40
41
|
"rules": {
|
|
41
42
|
"conditions/apply-consistent-blocks": "on",
|
|
42
43
|
"conditions/apply-comparison-order": "on",
|
|
44
|
+
"conditions/apply-equal": "on",
|
|
43
45
|
"conditions/apply-if": "on",
|
|
44
46
|
"conditions/add-return": "on",
|
|
45
47
|
"conditions/convert-comparison-to-boolean": "on",
|
|
@@ -141,6 +143,22 @@ Linter | Rule | Fix
|
|
|
141
143
|
🐊 **Putout**| [`conditions/apply-comparison-order`](https://github.com/coderaiser/putout/tree/master/packages/plugin-conditions/#apply-comparison-order)| ✅
|
|
142
144
|
⏣ **ESLint** | [`yoda`](https://eslint.org/docs/rules/yoda) | ½
|
|
143
145
|
|
|
146
|
+
## apply-equal
|
|
147
|
+
|
|
148
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/7ec940ad79df7e12a1d9111136b4a168/2ccea607e3232721eb950c18195168f8d9b4ef6a).
|
|
149
|
+
|
|
150
|
+
### ❌ Example of incorrect code
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
return a.b = c;
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### ✅ Example of correct code
|
|
157
|
+
|
|
158
|
+
```js
|
|
159
|
+
return a.b === c;
|
|
160
|
+
```
|
|
161
|
+
|
|
144
162
|
## apply-if
|
|
145
163
|
|
|
146
164
|
### ❌ Example of incorrect code
|
|
@@ -12,7 +12,7 @@ export const report = () => `Use consistent blocks`;
|
|
|
12
12
|
export const fix = (path) => {
|
|
13
13
|
const paths = getAllNodes(path);
|
|
14
14
|
|
|
15
|
-
if (isAllBlocks(paths))
|
|
15
|
+
if (isAllBlocks(paths)) {
|
|
16
16
|
for (const path of paths) {
|
|
17
17
|
if (isBlockStatement(path))
|
|
18
18
|
continue;
|
|
@@ -20,14 +20,17 @@ export const fix = (path) => {
|
|
|
20
20
|
const {node} = path;
|
|
21
21
|
replaceWith(path, blockStatement([node]));
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (const path of paths) {
|
|
28
|
+
if (!isBlockStatement(path))
|
|
29
|
+
continue;
|
|
30
|
+
|
|
31
|
+
const [node] = path.node.body;
|
|
32
|
+
replaceWith(path, node);
|
|
33
|
+
}
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
function isAllBlocks(paths) {
|
|
@@ -80,7 +83,7 @@ export const filter = (path) => {
|
|
|
80
83
|
continue;
|
|
81
84
|
|
|
82
85
|
if (first.leadingComments?.length)
|
|
83
|
-
|
|
86
|
+
return false;
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
blocks.push(is);
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as applyEqual from './apply-equal/index.js';
|
|
1
2
|
import * as applyConsistentBlocks from './apply-consistent-blocks/index.js';
|
|
2
3
|
import * as applyComparisonOrder from './apply-comparison-order/index.js';
|
|
3
4
|
import * as applyIf from './apply-if/index.js';
|
|
@@ -6,7 +7,7 @@ import * as convertComparisonToBoolean from './convert-comparison-to-boolean/ind
|
|
|
6
7
|
import * as convertEqualToStrictEqual from './convert-equal-to-strict-equal/index.js';
|
|
7
8
|
import * as mergeIfStatements from './merge-if-statements/index.js';
|
|
8
9
|
import * as removeBoolean from './remove-boolean/index.js';
|
|
9
|
-
import removeZero from './remove-zero/index.js';
|
|
10
|
+
import * as removeZero from './remove-zero/index.js';
|
|
10
11
|
import * as removeUselessElse from './remove-useless-else/index.js';
|
|
11
12
|
import * as simplify from './simplify/index.js';
|
|
12
13
|
import * as removeSameValuesCondition from './remove-same-values-condition/index.js';
|
|
@@ -36,4 +37,5 @@ export const rules = {
|
|
|
36
37
|
'wrap-with-block': wrapWithBlock,
|
|
37
38
|
'remove-useless-loop-condition': removeUselessLoopCondition,
|
|
38
39
|
'merge-if-with-else': mergeIfWithElse,
|
|
40
|
+
'apply-equal': applyEqual,
|
|
39
41
|
};
|
package/lib/remove-zero/index.js
CHANGED
package/package.json
CHANGED