Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check elseClause inside noUselessLoneBlockStatements #584

Merged
merged 11 commits into from
Oct 23, 2023
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;
}
```