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>
This commit is contained in:
Tapan Prakash 2024-10-22 06:31:44 +05:30 committed by GitHub
parent ab0353553a
commit 619d06f004
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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();
}