@putout/plugin-conditions 1.0.2 → 1.0.3

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
@@ -101,15 +101,13 @@ const t = false;
101
101
  ### ❌ Example of incorrect code
102
102
 
103
103
  ```js
104
- if (a == b) {
105
- }
104
+ if (a == b) {}
106
105
  ```
107
106
 
108
107
  ### ✅ Example of correct code
109
108
 
110
109
  ```js
111
- if (a === b) {
112
- }
110
+ if (a === b) {}
113
111
  ```
114
112
 
115
113
  ## evaluate
@@ -186,8 +184,7 @@ if (zone?.tooltipCallback) {
186
184
  }
187
185
 
188
186
  if (a)
189
- alert('hello');
190
- else
187
+ alert('hello');else
191
188
  alert('hello');
192
189
  ```
193
190
 
@@ -10,10 +10,14 @@ module.exports.filter = (path) => {
10
10
  if (!nextPath.node)
11
11
  return false;
12
12
 
13
- return path.get('consequent').isEmptyStatement();
13
+ return path
14
+ .get('consequent')
15
+ .isEmptyStatement();
14
16
  };
15
17
 
16
- module.exports.include = () => ['IfStatement'];
18
+ module.exports.include = () => [
19
+ 'IfStatement',
20
+ ];
17
21
 
18
22
  module.exports.fix = (path) => {
19
23
  const nextPath = path.getNextSibling();
@@ -5,7 +5,11 @@ const {
5
5
  operator,
6
6
  } = require('putout');
7
7
 
8
- const {replaceWith, compute} = operator;
8
+ const {
9
+ replaceWith,
10
+ compute,
11
+ } = operator;
12
+
9
13
  const {
10
14
  isIdentifier,
11
15
  BooleanLiteral,
@@ -11,4 +11,3 @@ module.exports.replace = () => ({
11
11
  '__a == __b': '__a === __b',
12
12
  '__a != __b': '__a !== __b',
13
13
  });
14
-
@@ -22,4 +22,3 @@ module.exports.replace = () => ({
22
22
  return '__b';
23
23
  },
24
24
  });
25
-
package/lib/index.js CHANGED
@@ -13,4 +13,3 @@ module.exports.rules = {
13
13
  ...getRule('remove-boolean'),
14
14
  ...getRule('simplify'),
15
15
  };
16
-
@@ -5,19 +5,14 @@ module.exports.report = () => 'Avoid boolean in assertions';
5
5
  module.exports.replace = () => ({
6
6
  'return __a === true': 'return Boolean(__a)',
7
7
  'return __a == true': 'return Boolean(__a)',
8
-
9
- 'const __a = __b === true': 'const __a = __b === Boolean(__a)',
10
- 'const __a = __b == true': 'const __a = __b == Boolean(__a)',
11
-
8
+ 'const __a = __b === true': 'const __a = __b',
9
+ 'const __a = __b == true': 'const __a = __b',
12
10
  '__a = __b === true': '__a = __b === Boolean(__a)',
13
11
  '__a = __b == true': '__a = __b == Boolean(__a)',
14
-
15
12
  '__a === true': '__a',
16
13
  '__a === false': '!__a',
17
14
  '__a == true': '__a',
18
15
  '__a == false': '!__a',
19
-
20
16
  '__a !== true': '!__a',
21
17
  '__a != true': '!__a',
22
18
  });
23
-
@@ -12,6 +12,7 @@ const {
12
12
  replaceWithMultiple,
13
13
  remove,
14
14
  } = operator;
15
+
15
16
  const {isIdentifier} = types;
16
17
 
17
18
  module.exports.report = () => 'Avoid constant conditions';
@@ -22,9 +23,7 @@ module.exports.fix = ({path, result}) => {
22
23
  consequent,
23
24
  } = path.node;
24
25
 
25
- const {
26
- body = [consequent],
27
- } = consequent;
26
+ const {body = [consequent]} = consequent;
28
27
 
29
28
  if (result)
30
29
  return replaceWithMultiple(path, body);
@@ -38,6 +37,7 @@ module.exports.fix = ({path, result}) => {
38
37
  module.exports.traverse = ({push, generate}) => ({
39
38
  IfStatement(path) {
40
39
  const testPath = path.get('test');
40
+
41
41
  const {
42
42
  left,
43
43
  right,
@@ -78,4 +78,3 @@ function containsIdentifiers(testPath) {
78
78
 
79
79
  return is;
80
80
  }
81
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-conditions",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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",
@@ -32,13 +32,12 @@
32
32
  "conditions"
33
33
  ],
34
34
  "devDependencies": {
35
- "@putout/plugin-convert-for-each-to-for-of": "^8.1.0",
36
- "@putout/plugin-remove-useless-variables": "^7.3.0",
35
+ "@putout/plugin-for-of": "*",
37
36
  "@putout/test": "^6.0.0",
38
37
  "c8": "^7.5.0",
39
38
  "eslint": "^8.0.1",
40
39
  "eslint-plugin-n": "^15.2.4",
41
- "eslint-plugin-putout": "^16.0.0",
40
+ "eslint-plugin-putout": "^17.0.0",
42
41
  "lerna": "^6.0.1",
43
42
  "madrun": "^9.0.0",
44
43
  "montag": "^1.2.1",