mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(linter): false positive in eslint/no-lone-blocks (#8587)
closes #8515
This commit is contained in:
parent
ee8ee55cda
commit
c15af02e52
2 changed files with 15 additions and 12 deletions
|
|
@ -63,7 +63,9 @@ impl Rule for NoLoneBlocks {
|
|||
|
||||
let body = &stmt.body;
|
||||
if body.is_empty() {
|
||||
report(ctx, node, parent_node);
|
||||
if !matches!(parent_node.kind(), AstKind::TryStatement(_) | AstKind::CatchClause(_)) {
|
||||
report(ctx, node, parent_node);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -206,6 +208,8 @@ fn test() {
|
|||
{
|
||||
await using x = makeDisposable();
|
||||
}", // { "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![
|
||||
|
|
@ -213,20 +217,20 @@ fn test() {
|
|||
"{var x = 1;}",
|
||||
"foo(); {} bar();",
|
||||
"if (foo) { bar(); {} baz(); }",
|
||||
"{
|
||||
"{
|
||||
{ } }",
|
||||
"function foo() { bar(); {} baz(); }",
|
||||
"while (foo) { {} }",
|
||||
// MEMO: Currently, this rule always analyzes in strict mode (as it cannot retrieve ecmaFeatures).
|
||||
// "{ function bar() {} }", // { "ecmaVersion": 6 },
|
||||
"{var x = 1;}", // { "ecmaVersion": 6 },
|
||||
"{
|
||||
"{
|
||||
{var x = 1;}
|
||||
let y = 2; } {let z = 1;}", // { "ecmaVersion": 6 },
|
||||
"{
|
||||
"{
|
||||
{let x = 1;}
|
||||
var y = 2; } {let z = 1;}", // { "ecmaVersion": 6 },
|
||||
"{
|
||||
"{
|
||||
{var x = 1;}
|
||||
var y = 2; }
|
||||
{var z = 1;}", // { "ecmaVersion": 6 },
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
---
|
||||
source: crates/oxc_linter/src/tester.rs
|
||||
snapshot_kind: text
|
||||
---
|
||||
⚠ eslint(no-lone-blocks): Block is unnecessary.
|
||||
╭─[no_lone_blocks.tsx:1:1]
|
||||
|
|
@ -28,13 +27,13 @@ snapshot_kind: text
|
|||
|
||||
⚠ eslint(no-lone-blocks): Block is unnecessary.
|
||||
╭─[no_lone_blocks.tsx:1:1]
|
||||
1 │ ╭─▶ {
|
||||
1 │ ╭─▶ {
|
||||
2 │ ╰─▶ { } }
|
||||
╰────
|
||||
|
||||
⚠ eslint(no-lone-blocks): Nested block is redundant.
|
||||
╭─[no_lone_blocks.tsx:2:4]
|
||||
1 │ {
|
||||
1 │ {
|
||||
2 │ { } }
|
||||
· ───
|
||||
╰────
|
||||
|
|
@ -59,7 +58,7 @@ snapshot_kind: text
|
|||
|
||||
⚠ eslint(no-lone-blocks): Nested block is redundant.
|
||||
╭─[no_lone_blocks.tsx:2:4]
|
||||
1 │ {
|
||||
1 │ {
|
||||
2 │ {var x = 1;}
|
||||
· ────────────
|
||||
3 │ let y = 2; } {let z = 1;}
|
||||
|
|
@ -67,14 +66,14 @@ snapshot_kind: text
|
|||
|
||||
⚠ eslint(no-lone-blocks): Block is unnecessary.
|
||||
╭─[no_lone_blocks.tsx:1:1]
|
||||
1 │ ╭─▶ {
|
||||
1 │ ╭─▶ {
|
||||
2 │ │ {let x = 1;}
|
||||
3 │ ╰─▶ var y = 2; } {let z = 1;}
|
||||
╰────
|
||||
|
||||
⚠ eslint(no-lone-blocks): Block is unnecessary.
|
||||
╭─[no_lone_blocks.tsx:1:1]
|
||||
1 │ ╭─▶ {
|
||||
1 │ ╭─▶ {
|
||||
2 │ │ {var x = 1;}
|
||||
3 │ ╰─▶ var y = 2; }
|
||||
4 │ {var z = 1;}
|
||||
|
|
@ -82,7 +81,7 @@ snapshot_kind: text
|
|||
|
||||
⚠ eslint(no-lone-blocks): Nested block is redundant.
|
||||
╭─[no_lone_blocks.tsx:2:4]
|
||||
1 │ {
|
||||
1 │ {
|
||||
2 │ {var x = 1;}
|
||||
· ────────────
|
||||
3 │ var y = 2; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue