From 619d06f00479407ff494acdb72a54d20dffe1f85 Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Tue, 22 Oct 2024 06:31:44 +0530 Subject: [PATCH] feat(linter): Fix suggestion for `eslint:no_empty_static_block` rule (#6732) Relates to https://github.com/oxc-project/oxc/issues/4179 --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../src/rules/eslint/no_empty_static_block.rs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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(); }