Skip to content

Commit

Permalink
feat(linter): Fix suggestion for eslint:no_empty_static_block rule (#…
Browse files Browse the repository at this point in the history
…6732)

Relates to #4179

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
tapanprakasht and autofix-ci[bot] authored Oct 22, 2024
1 parent ab03535 commit 619d06f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions crates/oxc_linter/src/rules/eslint/no_empty_static_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ declare_oxc_lint!(
/// ```
NoEmptyStaticBlock,
correctness,
pending // TODO: add a safe suggestion
suggestion,
);

impl Rule for NoEmptyStaticBlock {
Expand All @@ -58,7 +58,10 @@ impl Rule for NoEmptyStaticBlock {
if ctx.semantic().has_comments_between(static_block.span) {
return;
}
ctx.diagnostic(no_empty_static_block_diagnostic(static_block.span));
ctx.diagnostic_with_suggestion(
no_empty_static_block_diagnostic(static_block.span),
|fixer| fixer.delete(&static_block.span),
);
}
}
}
Expand Down Expand Up @@ -86,5 +89,17 @@ fn test() {
"class Foo { static { bar(); } static {} }",
];

Tester::new(NoEmptyStaticBlock::NAME, pass, fail).test_and_snapshot();
let fix = vec![
("class Foo { static {} }", "class Foo { }"),
("class Foo { static { } }", "class Foo { }"),
(
"class Foo { static {
} }",
"class Foo { }",
),
("class Foo { static { bar(); } static {} }", "class Foo { static { bar(); } }"),
];

Tester::new(NoEmptyStaticBlock::NAME, pass, fail).expect_fix(fix).test_and_snapshot();
}

0 comments on commit 619d06f

Please sign in to comment.