@putout/plugin-conditions 6.2.0 → 6.3.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 +28 -1
- package/lib/index.js +2 -0
- package/lib/wrap-with-block/index.js +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ npm i @putout/plugin-conditions -D
|
|
|
29
29
|
- ✅ [remove-useless-else](#remove-ureless-else);
|
|
30
30
|
- ✅ [remove-zero](#remove-zero);
|
|
31
31
|
- ✅ [simplify](#simplify);
|
|
32
|
+
- ✅ [wrap-with-block](#wrap-with-block);
|
|
32
33
|
|
|
33
34
|
## Config
|
|
34
35
|
|
|
@@ -49,7 +50,9 @@ npm i @putout/plugin-conditions -D
|
|
|
49
50
|
"conditions/remove-zero": "on",
|
|
50
51
|
"conditions/remove-useless-else": "on",
|
|
51
52
|
"conditions/remove-same-values-condition": "on",
|
|
52
|
-
"conditions/merge-if-statements": "on"
|
|
53
|
+
"conditions/merge-if-statements": "on",
|
|
54
|
+
"conditions/simplify": "on",
|
|
55
|
+
"conditions/wrap-with-block": "on"
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
```
|
|
@@ -431,6 +434,30 @@ for (const [i, el] of entries(elements)) {
|
|
|
431
434
|
}
|
|
432
435
|
```
|
|
433
436
|
|
|
437
|
+
## wrap-with-block
|
|
438
|
+
|
|
439
|
+
> If you use a declaration instead of a statement, it would be a `SyntaxError`. For example, a `let` declaration is not a statement, so you can't use it in its bare form as the body of an if statement.
|
|
440
|
+
>
|
|
441
|
+
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements#difference_between_statements_and_declarations)
|
|
442
|
+
|
|
443
|
+
Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/256b1b6a904b0352c3a2716d365185ca/fac1c6365c01539392c674e2ca7468ee062e73e8).
|
|
444
|
+
|
|
445
|
+
### ❌ Example of incorrect code
|
|
446
|
+
|
|
447
|
+
```js
|
|
448
|
+
const a = 5;
|
|
449
|
+
|
|
450
|
+
if (a) {}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### ✅ Example of correct code
|
|
454
|
+
|
|
455
|
+
```js
|
|
456
|
+
if (a) {
|
|
457
|
+
const a = 5;
|
|
458
|
+
}
|
|
459
|
+
```
|
|
460
|
+
|
|
434
461
|
### Comparison
|
|
435
462
|
|
|
436
463
|
Linter | Rule | Fix
|
package/lib/index.js
CHANGED
|
@@ -15,6 +15,7 @@ const removeSameValuesCondition = require('./remove-same-values-condition');
|
|
|
15
15
|
const addReturn = require('./add-return');
|
|
16
16
|
const convertArrowToCondition = require('./convert-arrow-to-condition');
|
|
17
17
|
const reverseCondition = require('./reverse-condition');
|
|
18
|
+
const wrapWithBlock = require('./wrap-with-block');
|
|
18
19
|
|
|
19
20
|
module.exports.rules = {
|
|
20
21
|
'apply-comparison-order': applyComparisonOrder,
|
|
@@ -32,4 +33,5 @@ module.exports.rules = {
|
|
|
32
33
|
'add-return': addReturn,
|
|
33
34
|
'convert-arrow-to-condition': convertArrowToCondition,
|
|
34
35
|
'reverse-condition': reverseCondition,
|
|
36
|
+
'wrap-with-block': wrapWithBlock,
|
|
35
37
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.report = () => `Lexical declaration cannot appear in single-statement-context`;
|
|
4
|
+
|
|
5
|
+
module.exports.match = () => ({
|
|
6
|
+
'const __a = __b': (vars, path) => {
|
|
7
|
+
return path.parentPath.isIfStatement();
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
module.exports.replace = () => ({
|
|
12
|
+
'const __a = __b': '{const __a = __b}',
|
|
13
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-conditions",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.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",
|