From 2c51b45354a80302c076a6ec16e272deed342ffa Mon Sep 17 00:00:00 2001 From: Tapan Prakash Date: Mon, 21 Oct 2024 13:32:26 +0530 Subject: [PATCH 1/2] feat(linter): Fix suggestion for `eslint:no_empty_static_block` rule --- .../src/rules/eslint/no_empty_static_block.rs | 16 +++++++++++++--- 1 file changed, 13 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..d21059adee6d6 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,7 @@ 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 +86,15 @@ 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(); } From cb245ab02b9b44e1319a4fc29abfa842ad5b56d8 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 08:04:20 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- .../src/rules/eslint/no_empty_static_block.rs | 11 ++++++++--- 1 file changed, 8 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 d21059adee6d6..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 @@ -58,7 +58,10 @@ impl Rule for NoEmptyStaticBlock { if ctx.semantic().has_comments_between(static_block.span) { return; } - ctx.diagnostic_with_suggestion(no_empty_static_block_diagnostic(static_block.span), |fixer| fixer.delete(&static_block.span)); + ctx.diagnostic_with_suggestion( + no_empty_static_block_diagnostic(static_block.span), + |fixer| fixer.delete(&static_block.span), + ); } } } @@ -89,10 +92,12 @@ fn test() { let fix = vec![ ("class Foo { static {} }", "class Foo { }"), ("class Foo { static { } }", "class Foo { }"), - ("class Foo { static { + ( + "class Foo { static { } }", - "class Foo { }"), + "class Foo { }", + ), ("class Foo { static { bar(); } static {} }", "class Foo { static { bar(); } }"), ];