From cf71c23d937cfda78ed8e8bc68ebb38f645aa177 Mon Sep 17 00:00:00 2001 From: rzvxa <3788964+rzvxa@users.noreply.github.com> Date: Fri, 14 Jun 2024 08:37:16 +0000 Subject: [PATCH] fix(linter): edge case with infinite loops. (#3672) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #3663 this time for real😅 browser search doesn't work in the GitHub actions (because of the partial rendering I guess) I had to use GitHub's own log search to see all instances related to this rule. [oxlint-ecosystem-ci](https://github.com/rzvxa/oxlint-ecosystem-ci/actions/runs/9512820948) --- .../oxc_linter/src/rules/eslint/no_unreachable.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/no_unreachable.rs b/crates/oxc_linter/src/rules/eslint/no_unreachable.rs index da24a6215..a988c41cb 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unreachable.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unreachable.rs @@ -6,7 +6,7 @@ use oxc_semantic::{ visit::{depth_first_search, Control, DfsEvent, EdgeRef}, Direction, }, - EdgeType, InstructionKind, + EdgeType, ErrorEdgeKind, InstructionKind, }; use oxc_span::{GetSpan, Span}; @@ -84,7 +84,9 @@ impl Rule for NoUnreachable { // `NewFunction` is always reachable | EdgeType::NewFunction // `Finalize` can be reachable if we encounter an error in the loop. - | EdgeType::Finalize => true, + | EdgeType::Finalize + // Explicit `Error` can also be reachable if we encounter an error in the loop. + | EdgeType::Error(ErrorEdgeKind::Explicit) => true, // If we have an incoming `Jump` and it is from a `Break` instruction, // We know with high confidence that we are visiting a reachable block. @@ -256,6 +258,15 @@ fn test() { } c(); ", + " + try { + while (true) { + a(); + } + } catch { + b(); + } + ", ]; let fail = vec![