@putout/plugin-conditions 1.1.0 → 2.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
@@ -175,7 +175,7 @@ function hi(b) {
175
175
  }
176
176
  ```
177
177
 
178
- ## remove-zero-
178
+ ## remove-zero
179
179
 
180
180
  ### ❌ Example of incorrect code
181
181
 
@@ -203,7 +203,8 @@ if (zone?.tooltipCallback) {
203
203
  }
204
204
 
205
205
  if (a)
206
- alert('hello');else
206
+ alert('hello');
207
+ else
207
208
  alert('hello');
208
209
  ```
209
210
 
@@ -51,10 +51,7 @@ function isLeftValid(leftPath) {
51
51
  if (leftPath.isIdentifier() || leftPath.isMemberExpression() || leftPath.isCallExpression())
52
52
  return false;
53
53
 
54
- if (leftPath.isOptionalMemberExpression())
55
- return false;
56
-
57
- return true;
54
+ return !leftPath.isOptionalMemberExpression();
58
55
  }
59
56
 
60
57
  function convertOperator(operator) {
@@ -1,19 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- types,
5
- operator,
6
- } = require('putout');
3
+ const {types, operator} = require('putout');
7
4
 
8
- const {
9
- replaceWith,
10
- compute,
11
- } = operator;
5
+ const {replaceWith, compute} = operator;
12
6
 
13
- const {
14
- isIdentifier,
15
- BooleanLiteral,
16
- } = types;
7
+ const {isIdentifier, BooleanLiteral} = types;
17
8
 
18
9
  module.exports.report = () => 'Avoid constant conditions';
19
10
 
@@ -1,9 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {
4
- types,
5
- operator,
6
- } = require('putout');
3
+ const {types, operator} = require('putout');
7
4
 
8
5
  const {runInNewContext} = require('vm');
9
6
 
@@ -18,10 +15,7 @@ const {isIdentifier} = types;
18
15
  module.exports.report = () => 'Avoid constant conditions';
19
16
 
20
17
  module.exports.fix = ({path, result}) => {
21
- const {
22
- alternate,
23
- consequent,
24
- } = path.node;
18
+ const {alternate, consequent} = path.node;
25
19
 
26
20
  const {body = [consequent]} = consequent;
27
21
 
@@ -1,15 +1,17 @@
1
1
  'use strict';
2
2
 
3
+ const {isJSXExpressionContainer} = require('putout').types;
4
+
3
5
  const check = (vars, path) => {
4
6
  const {parentPath} = path;
5
7
 
6
- if (parentPath.isAssignmentExpression())
8
+ if (parentPath.find(isJSXExpressionContainer))
7
9
  return false;
8
10
 
9
- if (parentPath.isVariableDeclarator())
11
+ if (parentPath.isAssignmentExpression())
10
12
  return false;
11
13
 
12
- return true;
14
+ return !parentPath.isVariableDeclarator();
13
15
  };
14
16
 
15
17
  module.exports.report = () => 'Avoid zero in assertions';
@@ -17,6 +19,8 @@ module.exports.report = () => 'Avoid zero in assertions';
17
19
  module.exports.match = () => ({
18
20
  '__a !== 0': check,
19
21
  '__a != 0': check,
22
+ '__a === 0': check,
23
+ '__a == 0': check,
20
24
  });
21
25
 
22
26
  module.exports.replace = () => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-conditions",
3
- "version": "1.1.0",
3
+ "version": "2.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",
@@ -33,18 +33,18 @@
33
33
  ],
34
34
  "devDependencies": {
35
35
  "@putout/plugin-for-of": "*",
36
- "@putout/test": "^6.0.0",
37
- "c8": "^7.5.0",
36
+ "@putout/test": "^7.0.0",
37
+ "c8": "^8.0.0",
38
38
  "eslint": "^8.0.1",
39
- "eslint-plugin-n": "^15.2.4",
40
- "eslint-plugin-putout": "^17.0.0",
39
+ "eslint-plugin-n": "^16.0.0",
40
+ "eslint-plugin-putout": "^18.0.0",
41
41
  "lerna": "^6.0.1",
42
42
  "madrun": "^9.0.0",
43
43
  "montag": "^1.2.1",
44
- "nodemon": "^2.0.1"
44
+ "nodemon": "^3.0.1"
45
45
  },
46
46
  "peerDependencies": {
47
- "putout": ">=29"
47
+ "putout": ">=30"
48
48
  },
49
49
  "license": "MIT",
50
50
  "engines": {