@putout/plugin-conditions 4.1.0 → 4.2.1
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 +37 -1
- package/lib/add-return/index.js +8 -0
- package/lib/apply-consistent-blocks/index.js +1 -1
- package/lib/index.js +2 -0
- package/lib/remove-constant/index.js +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -13,12 +13,30 @@ npm i @putout/plugin-conditions -D
|
|
|
13
13
|
|
|
14
14
|
## Rules
|
|
15
15
|
|
|
16
|
+
- ✅ [add-return](#add-return);
|
|
17
|
+
- ✅ [apply-comparison-order](#apply-comparison-order);
|
|
18
|
+
- ✅ [apply-consistent-blocks](#apply-consistent-blocks);
|
|
19
|
+
- ✅ [apply-if](#apply-if);
|
|
20
|
+
- ✅ [convert-comparison-to-boolean](#convert-comparison-to-boolean);
|
|
21
|
+
- ✅ [convert-equal-to-strict-equal](#convert-equal-to-strict-equal);
|
|
22
|
+
- ✅ [evaluate](#evaluate);
|
|
23
|
+
- ✅ [merge-if-statements](#merge-if-statements);
|
|
24
|
+
- ✅ [remove-boolean](#remove-boolean);
|
|
25
|
+
- ✅ [remove-constant](#remove-constant);
|
|
26
|
+
- ✅ [remove-same-values-condition](hremove-same-values-condition);
|
|
27
|
+
- ✅ [remove-useless-else](#remove-ureless-else);
|
|
28
|
+
- ✅ [remove-zero](#remove-zero);
|
|
29
|
+
- ✅ [simplify](#simplify);
|
|
30
|
+
|
|
31
|
+
## Config
|
|
32
|
+
|
|
16
33
|
```json
|
|
17
34
|
{
|
|
18
35
|
"rules": {
|
|
19
36
|
"conditions/apply-consistent-blocks": "on",
|
|
20
37
|
"conditions/apply-comparison-order": "on",
|
|
21
38
|
"conditions/apply-if": "on",
|
|
39
|
+
"conditions/add-return": "on",
|
|
22
40
|
"conditions/convert-comparison-to-boolean": "on",
|
|
23
41
|
"conditions/convert-equal-to-strict-equal": "on",
|
|
24
42
|
"conditions/evaluate": "on",
|
|
@@ -127,6 +145,24 @@ if (2 > 3)
|
|
|
127
145
|
alert();
|
|
128
146
|
```
|
|
129
147
|
|
|
148
|
+
## add-return
|
|
149
|
+
|
|
150
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/b1c12a29951659bb54b283310027d6ef/b32270ca22a36728c67edf0dc0f0519876b78f16).
|
|
151
|
+
|
|
152
|
+
### ❌ Example of incorrect code
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
if (a)
|
|
156
|
+
false;
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### ✅ Example of correct code
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
if (a)
|
|
163
|
+
return false;
|
|
164
|
+
```
|
|
165
|
+
|
|
130
166
|
## convert-comparison-to-boolean
|
|
131
167
|
|
|
132
168
|
> 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.
|
|
@@ -317,7 +353,7 @@ if (x)
|
|
|
317
353
|
console.log();
|
|
318
354
|
```
|
|
319
355
|
|
|
320
|
-
## remove-same-values-condition
|
|
356
|
+
## remove-same-values-condition
|
|
321
357
|
|
|
322
358
|
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/e537d4ec636d4a9b849063a8326b70ae/661041b3fbb1e3678bf7f828e4c8bf6ca723f89d).
|
|
323
359
|
|
|
@@ -35,7 +35,7 @@ module.exports.match = () => ({
|
|
|
35
35
|
module.exports.replace = () => ({
|
|
36
36
|
'if (__a) {if (__b) {__c}}': 'if (__a) if (__b) __c',
|
|
37
37
|
'if (__a) {__b}': 'if (__a) __b',
|
|
38
|
-
'if (__a) {__b} else {__c}':
|
|
38
|
+
'if (__a) {__b} else {__c}': 'if (__a) __b; else __c',
|
|
39
39
|
'if (__a) __b; else __body': 'if (__a) {__b} else __body',
|
|
40
40
|
'if (__a) __body; else __b': ({__b}, path) => {
|
|
41
41
|
if (isBlockStatement(__b))
|
package/lib/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const removeZero = require('./remove-zero');
|
|
|
12
12
|
const removeUselessElse = require('./remove-useless-else');
|
|
13
13
|
const simplify = require('./simplify');
|
|
14
14
|
const removeSameValuesCondition = require('./remove-same-values-condition');
|
|
15
|
+
const addReturn = require('./add-return');
|
|
15
16
|
|
|
16
17
|
module.exports.rules = {
|
|
17
18
|
'apply-comparison-order': applyComparisonOrder,
|
|
@@ -26,4 +27,5 @@ module.exports.rules = {
|
|
|
26
27
|
'remove-useless-else': removeUselessElse,
|
|
27
28
|
simplify,
|
|
28
29
|
'remove-same-values-condition': removeSameValuesCondition,
|
|
30
|
+
'add-return': addReturn,
|
|
29
31
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-conditions",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
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",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@putout/plugin-for-of": "*",
|
|
36
|
-
"@putout/test": "^
|
|
37
|
-
"c8": "^
|
|
38
|
-
"eslint": "^
|
|
39
|
-
"eslint-plugin-n": "^
|
|
40
|
-
"eslint-plugin-putout": "^
|
|
36
|
+
"@putout/test": "^9.0.0",
|
|
37
|
+
"c8": "^9.0.0",
|
|
38
|
+
"eslint": "^9.0.0",
|
|
39
|
+
"eslint-plugin-n": "^17.0.0",
|
|
40
|
+
"eslint-plugin-putout": "^22.0.0",
|
|
41
41
|
"lerna": "^6.0.1",
|
|
42
|
-
"madrun": "^
|
|
42
|
+
"madrun": "^10.0.0",
|
|
43
43
|
"montag": "^1.2.1",
|
|
44
44
|
"nodemon": "^3.0.1"
|
|
45
45
|
},
|