Skip to content

Commit 4f5e70b

Browse files
committed
featur: @putout/plugin-conditions: apply-consistent-blocks: exclude VariableDeclaration
1 parent 5424d44 commit 4f5e70b

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if (notEmpty) {
2+
delta = end - currentTokenIndex;
3+
index = end - templateIndex;
4+
} else {
5+
continue;
6+
}

packages/plugin-conditions/lib/apply-consistent-blocks/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const {replaceWith} = operator;
55
const {
66
isBlockStatement,
77
BlockStatement,
8-
isExpressionStatement,
9-
isIfStatement,
8+
isVariableDeclaration,
109
} = types;
1110

1211
module.exports.report = () => `Use consistent blocks`;
@@ -75,7 +74,7 @@ module.exports.filter = (path) => {
7574
if (is && body.length === 1) {
7675
const [first] = body;
7776

78-
if (!isExpressionStatement(first) && !isIfStatement(first))
77+
if (isVariableDeclaration(first))
7978
continue;
8079
}
8180

packages/plugin-conditions/lib/apply-consistent-blocks/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ test('putout: apply-consistent-blocks: no report: couple-blocks', (t) => {
5959
t.end();
6060
});
6161

62+
test('putout: apply-consistent-blocks: no report: else-statement', (t) => {
63+
t.noReport('else-statement');
64+
t.end();
65+
});
66+
6267
test('putout: apply-consistent-blocks: no report after transform', (t) => {
6368
t.noReportAfterTransform('nested');
6469
t.end();

0 commit comments

Comments
 (0)