@putout/plugin-conditions 6.1.0 → 6.2.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.
@@ -5,6 +5,8 @@ const {replaceWith} = operator;
5
5
  const {
6
6
  isBlockStatement,
7
7
  BlockStatement,
8
+ isExpressionStatement,
9
+ isIfStatement,
8
10
  } = types;
9
11
 
10
12
  module.exports.report = () => `Use consistent blocks`;
@@ -63,11 +65,20 @@ module.exports.filter = (path) => {
63
65
  if (path === path.parentPath.get('alternate'))
64
66
  return false;
65
67
 
66
- const nodes = getAllNodes(path);
68
+ const paths = getAllNodes(path);
67
69
  const blocks = [];
68
70
 
69
- for (const node of nodes) {
70
- const is = isBlockStatement(node);
71
+ for (const path of paths) {
72
+ const is = isBlockStatement(path);
73
+ const {body} = path.node;
74
+
75
+ if (is && body.length === 1) {
76
+ const [first] = body;
77
+
78
+ if (!isExpressionStatement(first) && !isIfStatement(first))
79
+ continue;
80
+ }
81
+
71
82
  blocks.push(is);
72
83
  }
73
84
 
@@ -78,8 +89,8 @@ module.exports.filter = (path) => {
78
89
 
79
90
  const couple = [];
80
91
 
81
- for (const node of nodes) {
82
- const is = isBlockStatement(node) && node.node.body.length > 1;
92
+ for (const path of paths) {
93
+ const is = isBlockStatement(path) && path.node.body.length > 1;
83
94
  couple.push(is);
84
95
  }
85
96
 
@@ -88,10 +99,10 @@ module.exports.filter = (path) => {
88
99
  if (!coupleCount)
89
100
  return true;
90
101
 
91
- if (coupleCount === nodes.length)
102
+ if (coupleCount === paths.length)
92
103
  return false;
93
104
 
94
- return !(count !== 1 && count === nodes.length);
105
+ return !(count !== 1 && count === paths.length);
95
106
  };
96
107
 
97
108
  function getAllNodes(path, nodes = []) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-conditions",
3
- "version": "6.1.0",
3
+ "version": "6.2.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",