Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Jul 11, 2024
1 parent 5a2fab5 commit 059deab
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 17 deletions.
16 changes: 6 additions & 10 deletions crates/oxc_linter/src/rules/eslint/no_empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,16 @@ impl Rule for NoEmpty {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
match node.kind() {
AstKind::BlockStatement(block) if block.body.is_empty() => {
if ctx.semantic().trivias().has_comments_between(block.span) {
if self.allow_empty_catch
&& matches!(ctx.nodes().parent_kind(node.id()), Some(AstKind::CatchClause(_)))
{
return;
}
ctx.diagnostic(no_empty_diagnostic("block", block.span));
}
// The visitor does not visit the `BlockStatement` inside the `CatchClause`.
// See `Visit::visit_catch_clause`.
AstKind::CatchClause(catch_clause)
if !self.allow_empty_catch && catch_clause.body.body.is_empty() =>
{
if ctx.semantic().trivias().has_comments_between(catch_clause.body.span) {

if ctx.semantic().trivias().has_comments_between(block.span) {
return;
}
ctx.diagnostic(no_empty_diagnostic("block", catch_clause.body.span));
ctx.diagnostic(no_empty_diagnostic("block", block.span));
}
// The visitor does not visit the `BlockStatement` inside the `FinallyClause`.
// See `Visit::visit_finally_clause`.
Expand Down
7 changes: 0 additions & 7 deletions crates/oxc_linter/src/rules/unicorn/empty_brace_spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ impl Rule for EmptyBraceSpaces {
AstKind::BlockStatement(block_stmt) => {
remove_empty_braces_spaces(ctx, block_stmt.body.is_empty(), block_stmt.span);
}
AstKind::CatchClause(catch_clause) => {
remove_empty_braces_spaces(
ctx,
catch_clause.body.body.is_empty(),
catch_clause.body.span,
);
}
AstKind::FinallyClause(finally_clause) => {
remove_empty_braces_spaces(
ctx,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
source: crates/oxc_semantic/tests/integration/cfg.rs
assertion_line: 16
expression: snapshot
input_file: crates/oxc_semantic/tests/integration/cfg_fixtures/labeled_block_break.js
---
bb0: {

}

bb1: {
statement
}

bb2: {

}

bb3: {
statement
}

bb4: {
statement
statement
statement
statement
}

bb5: {
condition
}

bb6: {
statement
break <label>
}

bb7: {
unreachable
}

bb8: {

}

bb9: {

}

bb10: {

}

digraph {
0 [ label = "" ]
1 [ label = "TryStatement" ]
2 [ label = "" ]
3 [ label = "BlockStatement" ]
4 [ label = "BlockStatement\nLabeledStatement\nBlockStatement\nIfStatement" ]
5 [ label = "Condition(IdentifierReference(condition))" ]
6 [ label = "BlockStatement\nbreak <LABEL>" ]
7 [ label = "unreachable" ]
8 [ label = "" ]
9 [ label = "" ]
10 [ label = "" ]
1 -> 0 [ label = "Error(Implicit)" ]
3 -> 2 [ label = "Error(Explicit)" ]
4 -> 0 [ label = "Error(Implicit)" ]
2 -> 4 [ label = "Normal" ]
5 -> 0 [ label = "Error(Implicit)" ]
6 -> 0 [ label = "Error(Implicit)" ]
7 -> 0 [ label = "Error(Implicit)" , style = "dotted" ]
6 -> 7 [ label = "Unreachable" , style = "dotted" ]
8 -> 0 [ label = "Error(Implicit)" ]
4 -> 5 [ label = "Normal" ]
7 -> 8 [ label = "Normal" , style = "dotted" ]
5 -> 6 [ label = "Jump" ]
4 -> 8 [ label = "Normal" ]
9 -> 0 [ label = "Error(Implicit)" ]
8 -> 9 [ label = "Normal" ]
6 -> 9 [ label = "Jump" ]
10 -> 0 [ label = "Error(Implicit)" ]
1 -> 3 [ label = "Normal" ]
3 -> 10 [ label = "Normal" ]
9 -> 10 [ label = "Normal" ]
}

0 comments on commit 059deab

Please sign in to comment.