@putout/plugin-conditions 1.0.0 β 1.0.2
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 +21 -1
- package/lib/apply-if/index.js +24 -0
- package/lib/index.js +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ npm i @putout/plugin-conditions -D
|
|
|
17
17
|
{
|
|
18
18
|
"rules": {
|
|
19
19
|
"conditions/apply-comparison-order": "on",
|
|
20
|
+
"conditions/apply-if": "on",
|
|
20
21
|
"conditions/convert-comparison-to-boolean": "on",
|
|
21
22
|
"conditions/convert-equal-to-strict-equal": "on",
|
|
22
23
|
"conditions/evaluate": "on",
|
|
@@ -31,7 +32,7 @@ npm i @putout/plugin-conditions -D
|
|
|
31
32
|
> The result of evaluating an equality operator is always of type boolean based on whether the comparison is true.
|
|
32
33
|
>
|
|
33
34
|
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators)
|
|
34
|
-
|
|
35
|
+
|
|
35
36
|
Checkout it π[Putout Editor](https://putout.cloudcmd.io/#/gist/c61c94d2e1990f59b160aaf462f9a903/0855844b114079ec46098be6f3602dfdaa74290c).
|
|
36
37
|
|
|
37
38
|
### β Example of incorrect code
|
|
@@ -55,11 +56,30 @@ Linter | Rule | Fix
|
|
|
55
56
|
π **Putout**| [`conditions/apply-comparison-order`](https://github.com/coderaiser/putout/tree/master/packages/plugin-conditions/#apply-comparison-order)| β
|
|
56
57
|
β£ **ESLint** | [`yoda`](https://eslint.org/docs/rules/yoda) | Β½
|
|
57
58
|
|
|
59
|
+
## apply-if
|
|
60
|
+
|
|
61
|
+
### β Example of incorrect code
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
if (2 > 3)
|
|
65
|
+
;
|
|
66
|
+
|
|
67
|
+
alert();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### β
Example of correct code
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
if (2 > 3)
|
|
74
|
+
alert();
|
|
75
|
+
```
|
|
76
|
+
|
|
58
77
|
## convert-comparison-to-boolean
|
|
59
78
|
|
|
60
79
|
> 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.
|
|
61
80
|
>
|
|
62
81
|
> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness)
|
|
82
|
+
|
|
63
83
|
## β Example of incorrect code
|
|
64
84
|
|
|
65
85
|
```js
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {replaceWith} = require('putout').operator;
|
|
4
|
+
|
|
5
|
+
module.exports.report = () => 'Avoid empty statement in if condition';
|
|
6
|
+
|
|
7
|
+
module.exports.filter = (path) => {
|
|
8
|
+
const nextPath = path.getNextSibling();
|
|
9
|
+
|
|
10
|
+
if (!nextPath.node)
|
|
11
|
+
return false;
|
|
12
|
+
|
|
13
|
+
return path.get('consequent').isEmptyStatement();
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports.include = () => ['IfStatement'];
|
|
17
|
+
|
|
18
|
+
module.exports.fix = (path) => {
|
|
19
|
+
const nextPath = path.getNextSibling();
|
|
20
|
+
const consequentPath = path.get('consequent');
|
|
21
|
+
|
|
22
|
+
replaceWith(consequentPath, nextPath);
|
|
23
|
+
nextPath.remove();
|
|
24
|
+
};
|
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/plugin-conditions",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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",
|
|
7
|
-
"homepage": "https://github.com/coderaiser/
|
|
7
|
+
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-conditions#readme",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"release": false,
|
|
10
10
|
"tag": false,
|