@putout/plugin-conditions 1.0.3 → 1.1.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 CHANGED
@@ -22,7 +22,8 @@ npm i @putout/plugin-conditions -D
22
22
  "conditions/convert-equal-to-strict-equal": "on",
23
23
  "conditions/evaluate": "on",
24
24
  "conditions/remove-boolean": "on",
25
- "conditions/remove-constant": "on"
25
+ "conditions/remove-constant": "on",
26
+ "conditions/remove-zero": "on"
26
27
  }
27
28
  }
28
29
  ```
@@ -174,6 +175,24 @@ function hi(b) {
174
175
  }
175
176
  ```
176
177
 
178
+ ## remove-zero-
179
+
180
+ ### ❌ Example of incorrect code
181
+
182
+ ```js
183
+ if (b === 0) {}
184
+
185
+ if (b !== 0) {}
186
+ ```
187
+
188
+ ### ✅ Example of correct code
189
+
190
+ ```js
191
+ if (!b) {}
192
+
193
+ if (b) {}
194
+ ```
195
+
177
196
  ## simplify
178
197
 
179
198
  ## ❌ Example of incorrect code
package/lib/index.js CHANGED
@@ -11,5 +11,6 @@ module.exports.rules = {
11
11
  ...getRule('convert-comparison-to-boolean'),
12
12
  ...getRule('convert-equal-to-strict-equal'),
13
13
  ...getRule('remove-boolean'),
14
+ ...getRule('remove-zero'),
14
15
  ...getRule('simplify'),
15
16
  };
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const check = (vars, path) => {
4
+ const {parentPath} = path;
5
+
6
+ if (parentPath.isAssignmentExpression())
7
+ return false;
8
+
9
+ if (parentPath.isVariableDeclarator())
10
+ return false;
11
+
12
+ return true;
13
+ };
14
+
15
+ module.exports.report = () => 'Avoid zero in assertions';
16
+
17
+ module.exports.match = () => ({
18
+ '__a !== 0': check,
19
+ '__a != 0': check,
20
+ });
21
+
22
+ module.exports.replace = () => ({
23
+ '__a !== 0': '__a',
24
+ '__a != 0': '__a',
25
+ '__a === 0': '!__a',
26
+ '__a == 0': '!__a',
27
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-conditions",
3
- "version": "1.0.3",
3
+ "version": "1.1.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",