@putout/plugin-conditions 1.0.0 β†’ 1.0.1

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
@@ -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",
@@ -55,6 +56,22 @@ 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
+ alert();
66
+ ```
67
+
68
+ ### βœ… Example of correct code
69
+
70
+ ```js
71
+ if (2 > 3)
72
+ alert();
73
+ ```
74
+
58
75
  ## convert-comparison-to-boolean
59
76
 
60
77
  > 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.
@@ -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
@@ -6,6 +6,7 @@ const getRule = (a) => ({
6
6
 
7
7
  module.exports.rules = {
8
8
  ...getRule('apply-comparison-order'),
9
+ ...getRule('apply-if'),
9
10
  ...getRule('evaluate'),
10
11
  ...getRule('convert-comparison-to-boolean'),
11
12
  ...getRule('convert-equal-to-strict-equal'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-conditions",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",