@putout/plugin-conditions 1.0.1 β†’ 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
@@ -32,7 +32,7 @@ npm i @putout/plugin-conditions -D
32
32
  > The result of evaluating an equality operator is always of type boolean based on whether the comparison is true.
33
33
  >
34
34
  > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators)
35
-
35
+
36
36
  Checkout it 🐊[Putout Editor](https://putout.cloudcmd.io/#/gist/c61c94d2e1990f59b160aaf462f9a903/0855844b114079ec46098be6f3602dfdaa74290c).
37
37
 
38
38
  ### ❌ Example of incorrect code
@@ -61,8 +61,10 @@ Linter | Rule | Fix
61
61
  ### ❌ Example of incorrect code
62
62
 
63
63
  ```js
64
- if (2 > 3);
65
- alert();
64
+ if (2 > 3)
65
+ ;
66
+
67
+ alert();
66
68
  ```
67
69
 
68
70
  ### βœ… Example of correct code
@@ -77,6 +79,7 @@ if (2 > 3)
77
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.
78
80
  >
79
81
  > (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness)
82
+
80
83
  ## ❌ Example of incorrect code
81
84
 
82
85
  ```js
@@ -98,15 +101,13 @@ const t = false;
98
101
  ### ❌ Example of incorrect code
99
102
 
100
103
  ```js
101
- if (a == b) {
102
- }
104
+ if (a == b) {}
103
105
  ```
104
106
 
105
107
  ### βœ… Example of correct code
106
108
 
107
109
  ```js
108
- if (a === b) {
109
- }
110
+ if (a === b) {}
110
111
  ```
111
112
 
112
113
  ## evaluate
@@ -183,8 +184,7 @@ if (zone?.tooltipCallback) {
183
184
  }
184
185
 
185
186
  if (a)
186
- alert('hello');
187
- else
187
+ alert('hello');else
188
188
  alert('hello');
189
189
  ```
190
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,10 +1,10 @@
1
1
  {
2
2
  "name": "@putout/plugin-conditions",
3
- "version": "1.0.1",
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",
7
- "homepage": "https://github.com/coderaiser/conditions/tree/master/packages/plugin-conditions#readme",
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,
@@ -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",