Skip to content

linter/no-unreachable: collapse duplicate diagnostics for the same unreachable region #21657

@camc314

Description

@camc314

What happened?

In the ecosystem CI run for oven-sh/bun, oxlint -c oxlint.json src/js reports 20 eslint(no-unreachable) errors. The output is much noisier than expected because the rule appears to report every nested statement/expression inside an unreachable region instead of one diagnostic for the unreachable region.

Run: https://github.com/oxc-project/oxc-ecosystem-ci/actions/runs/24795395393/job/72564872698

Example from the log

The command reports multiple diagnostics for the same unreachable block in src/js/internal/sql/postgres.ts:

× eslint(no-unreachable): Unreachable code.
   ╭─[src/js/internal/sql/postgres.ts:279:5]
279 │     $assert(result instanceof SQLResultArray, "Invalid result array");

× eslint(no-unreachable): Unreachable code.
   ╭─[src/js/internal/sql/postgres.ts:280:5]
280 │     if (typeof commandTag === "string") {

× eslint(no-unreachable): Unreachable code.
   ╭─[src/js/internal/sql/postgres.ts:280:41]
280 │     if (typeof commandTag === "string") {

× eslint(no-unreachable): Unreachable code.
   ╭─[src/js/internal/sql/postgres.ts:281:7]
281 │       if (commandTag.length > 0) {

× eslint(no-unreachable): Unreachable code.
   ╭─[src/js/internal/sql/postgres.ts:284:12]
284 │     } else {

× eslint(no-unreachable): Unreachable code.
   ╭─[src/js/internal/sql/postgres.ts:285:7]
285 │       result.command = cmds[commandTag];

A similar pattern occurs in src/js/node/_http_agent.ts: the rule reports the if, its condition, nested assignments, and following statements as separate no-unreachable errors. The job ends with:

Found 0 warnings and 20 errors.

Expected behavior

Report one no-unreachable diagnostic for each contiguous unreachable region, or at least suppress descendant diagnostics once a parent unreachable statement/range has already been reported.

For the Bun log above, the useful output would be closer to 1 diagnostic for the unreachable region in postgres.ts and 1 diagnostic for the unreachable region in _http_agent.ts, rather than 20 diagnostics.

Why this matters

The current output makes ecosystem CI failures harder to read and makes a single underlying control-flow issue look like many unrelated lint errors.

Notes

This is about diagnostic quality/noise reduction, not necessarily whether the code is considered unreachable. The main issue is duplicate/nested reporting for one unreachable region.

Metadata

Metadata

Assignees

Labels

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions