fix(lint): clear latent dead stores and a dropped assertion - #31
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prepares the ground for the eslint 10 upgrade, and fixes eleven real findings on its own merits.
ESLint 10 enables
no-useless-assignmentandpreserve-caught-errorin 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)
nodePathin the two pointer helpers was declared and seeded outside a loop that reassigns it to[]on every iteration, so it is now aconstscoped to the loop body.conditionReswas seededtrueand then assigned in both branches of the followingif/else. The formatting service seededresultwithtextDocument.getText()and overwrote it with the prettier output as the first statement of thetry, so the declaration moves to that assignment.getTextassigned''and then overwrote it in both branches of anif/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:
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: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:
That is a real behaviour, and the neighbouring
findNamespaceassertions already confirm the same document resolves to namespaceapidomwithout a content language andasyncapiwith one.test/openapi-json.tsandtest/asyncapi-yaml.ts— deliberately left unasserted. Both keep the call and lose only the assignment. Asserting them would mean inventing expectations:// valid specand 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.// 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
resultconst-eligible, soprefer-constapplied.Verification
main)npx eslint ./npx tsc --noEmitnpm testThe eslint 10 column is the point of the PR, and was checked by resolving eslint 10 into the tree without committing it:
no-useless-assignmentandpreserve-caught-errorreport no errors at all afterwards, down from 11. So the dependency bump that follows can land green.