Skip to content

Commit

Permalink
fix: check elseClause inside noUselessLoneBlockStatements (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasucp1207 authored Oct 23, 2023
1 parent 926173a commit d420a7f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use biome_console::markup;
use biome_diagnostics::Applicability;
use biome_js_factory::make;
use biome_js_syntax::{
AnyJsStatement, JsBlockStatement, JsFileSource, JsLabeledStatement, JsStatementList,
JsVariableStatement,
AnyJsStatement, JsBlockStatement, JsElseClause, JsFileSource, JsLabeledStatement,
JsStatementList, JsVariableStatement,
};
use biome_rowan::{AstNode, AstNodeList, BatchMutationExt};

Expand Down Expand Up @@ -145,6 +145,12 @@ fn statement_has_block_level_declaration(statement: &AnyJsStatement, is_module:
}

fn in_control_structure(block: &JsBlockStatement) -> bool {
if let Some(node) = block.syntax().parent() {
let syntax_kind = node.kind();
if JsElseClause::can_cast(syntax_kind) {
return true;
}
}
matches!(
block.parent(),
Some(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ function g() {

{
function foo() {}
}

if(x) {
x += 1;
} else {
x += 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ function g() {
{
function foo() {}
}

if(x) {
x += 1;
} else {
x += 2;
}
```


0 comments on commit d420a7f

Please sign in to comment.