Skip to content

fix(lint): clear latent dead stores and a dropped assertion - #31

Merged
frantuma merged 1 commit into
mainfrom
frantuma/fix-latent-lint-findings
Sep 12, 2026
Merged

frantuma merged 1 commit into
mainfrom
frantuma/fix-latent-lint-findings

Conversation

@frantuma

Copy link
Copy Markdown
Member

Prepares the ground for the eslint 10 upgrade, and fixes eleven real findings on its own merits.

ESLint 10 enables no-useless-assignment and preserve-caught-error in its recommended set. Both flag genuine problems in this repository, so they are fixed here — separately and reviewably — rather than buried inside a dependency bump.

Every change in this PR is valid under the eslint 9 currently on main; nothing here depends on the upgrade.

Dead stores (7)

nodePath in the two pointer helpers was declared and seeded outside a loop that reassigns it to [] on every iteration, so it is now a const scoped to the loop body. conditionRes was seeded true and then assigned in both branches of the following if/else. The formatting service seeded result with textDocument.getText() and overwrote it with the prettier output as the first statement of the try, so the declaration moves to that assignment. getText assigned '' and then overwrote it in both branches of an if/else, which is now a single conditional assignment.

A swallowed cause (1)

The formatting service catches a prettier failure, builds a message from it, and rethrows:

throw new Error(error);          // before — the prettier error is lost
throw new Error(error, { cause: e });  // after

The message already interpolated e.message, but the original error object — with its stack and any structured detail — was discarded. This is the one change with a runtime effect: consumers catching the error now get .cause.

Unasserted results (4) — the more interesting half

All four were calls whose result was thrown away. They are not treated identically, because they are not the same thing.

test/detect.ts, two sites — a dropped assertion, now restored. The file parses each fixture twice, once without a content language and once with, and asserts both. Every block does this except the two apidom fixtures, which parse twice and assert only the second. Rather than guess, I measured what the first parse returns:

apidom.json: parse(doc, undefined) -> api.element = undefined
apidom.yaml: parse(doc, undefined) -> api.element = undefined

An apidom-format document resolves to no api element without a content language — which is presumably exactly why the assertion was never written. It is now stated:

assert.isUndefined(result.api, 'an apidom document needs a content language to resolve');

That is a real behaviour, and the neighbouring findNamespace assertions already confirm the same document resolves to namespace apidom without a content language and asyncapi with one.

test/openapi-json.ts and test/asyncapi-yaml.ts — deliberately left unasserted. Both keep the call and lose only the assignment. Asserting them would mean inventing expectations:

  • openapi-json validates a spec commented // valid spec and discards the result before replacing the document. That spec actually produces 9 diagnostics, measured, not zero. Pinning nine unreviewed diagnostics into an assertion is not something this PR should do quietly.
  • asyncapi-yaml sits under an open // TODO yaml errors not recovered? no result? with a commented-out expectation block. Asserting current behaviour there would contradict the open question.

Keeping the call preserves what it still does — catch a throw — while removing the dead store. Both remain fair game for a follow-up that decides what they should assert.

One knock-on: dropping the reassignment in asyncapi-yaml made its result const-eligible, so prefer-const applied.

Verification

check eslint 9 (main) eslint 10
npx eslint ./ 0 errors, 14 warnings 0 errors, 14 warnings
npx tsc --noEmit exit 0
npm test 400 passing

The eslint 10 column is the point of the PR, and was checked by resolving eslint 10 into the tree without committing it: no-useless-assignment and preserve-caught-error report no errors at all afterwards, down from 11. So the dependency bump that follows can land green.

ESLint 10 turns on no-useless-assignment and preserve-caught-error in
its recommended set, and they flag eleven findings here. All of them
are real, so they are fixed ahead of the upgrade rather than with it.

Most are dead initialisers: nodePath and conditionRes in utils, the
result seed in the formatting service, and the empty string getText
assigns over in both branches. The formatting service also rethrows
without attaching what it caught, which loses the prettier error; it
now passes the original through as `cause`.

Four were unasserted results, which is the more interesting half.
detect.ts parses each fixture twice, once without a content language
and once with, and asserts both -- except for the two apidom fixtures,
where the first assertion is missing. Parsing those without a content
language resolves no api element at all, which is presumably why the
assertion was never written; it is now stated explicitly.

The other two stay unasserted on purpose. openapi-json validates a
spec whose result is dropped before the document is replaced, and
pinning it would mean recording nine diagnostics that nothing has
reviewed. asyncapi-yaml has an open TODO and a commented-out
expectation over its call. Both keep the call, which still catches a
throw, and lose only the dead assignment.
@frantuma
frantuma merged commit 278104e into main Sep 12, 2026
9 checks passed
@frantuma
frantuma deleted the frantuma/fix-latent-lint-findings branch September 12, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant