diff --git a/crates/oxc_linter/src/rules/eslint/no_empty_static_block.rs b/crates/oxc_linter/src/rules/eslint/no_empty_static_block.rs index 24de7dc61d01a..d0bf8780f98a0 100644 --- a/crates/oxc_linter/src/rules/eslint/no_empty_static_block.rs +++ b/crates/oxc_linter/src/rules/eslint/no_empty_static_block.rs @@ -48,7 +48,7 @@ declare_oxc_lint!( /// ``` NoEmptyStaticBlock, correctness, - pending // TODO: add a safe suggestion + suggestion, ); impl Rule for NoEmptyStaticBlock { @@ -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), + ); } } } @@ -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(); }