fix(linter): false positive in eslint/no-lone-blocks (#8587)

closes #8515
This commit is contained in:
dalaoshu 2025-01-19 00:08:57 +08:00 committed by GitHub
parent ee8ee55cda
commit c15af02e52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 12 deletions

View file

@ -63,7 +63,9 @@ impl Rule for NoLoneBlocks {
let body = &stmt.body; let body = &stmt.body;
if body.is_empty() { if body.is_empty() {
if !matches!(parent_node.kind(), AstKind::TryStatement(_) | AstKind::CatchClause(_)) {
report(ctx, node, parent_node); report(ctx, node, parent_node);
}
return; return;
} }
@ -206,6 +208,8 @@ fn test() {
{ {
await using x = makeDisposable(); await using x = makeDisposable();
}", // { "parser": require(parser("typescript-parsers/no-lone-blocks/await-using")), "ecmaVersion": 2022 } }", // { "parser": require(parser("typescript-parsers/no-lone-blocks/await-using")), "ecmaVersion": 2022 }
// Issue: <https://github.com/oxc-project/oxc/issues/8515>
"try {} catch {}",
]; ];
let fail = vec![ let fail = vec![

View file

@ -1,6 +1,5 @@
--- ---
source: crates/oxc_linter/src/tester.rs source: crates/oxc_linter/src/tester.rs
snapshot_kind: text
--- ---
⚠ eslint(no-lone-blocks): Block is unnecessary. ⚠ eslint(no-lone-blocks): Block is unnecessary.
╭─[no_lone_blocks.tsx:1:1] ╭─[no_lone_blocks.tsx:1:1]