chore: remove unused buildKeys module - #205
Merged
Merged
Conversation
`src/tsmorph/buildKeys.mts` has been dead code since the ts-morph migration (606ec44). Nothing under `src/` imports it and it is not re-exported from `src/tsmorph/index.mts`, so it was unreachable through any declared package export — `package.json` maps the package root only to `dist/generate.mjs`. (It was still compiled and published, since `files: ["dist"]` ships the whole output directory.) Its only consumer was its own test file. Worse, it is actively misleading: it emits a different naming scheme than the generator actually produces (`findPetsQueryKey` / `FindPetsQueryKeyFn` vs. the real `useFindPetsKey` / `UseFindPetsKeyFn`) and has no infinite-query support at all. Query keys are really built by `buildQueryKeyConst`, `buildMutationKeyConst`, `buildQueryKeyFn`, `buildMutationKeyFn`, `buildInfiniteQueryKeyConst` and `buildInfiniteQueryKeyFn` in `src/tsmorph/buildCommon.mts`, called from `generateFiles.mts`, so anyone reading `buildKeys.mts` to understand key generation is led to the wrong conclusion. Because the deleted module was at 100% coverage, dropping it lowers the aggregate branch coverage from 90.07% to 89.75%, under the 90% threshold. Two tests are added for the previously untested error and fallback paths in `buildGenerationContext` (missing service file, missing models file), which brings branches to 90.57% and raises `parseOperations.mts` branch coverage from 76% to 80%. The missing-models fallback is unreachable through real hey-api output — it always emits `types.gen` — so a hand-built project is the only way to cover it. Verified: `tsc -p tsconfig.json` clean, biome clean, 182 tests pass, and the generated example output is byte-identical before and after.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Coverage Report
File CoverageNo changed files found. |
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.
What
Deletes
src/tsmorph/buildKeys.mtsandtests/tsmorph/buildKeys.test.ts, and adds two tests totests/parseOperations.test.ts.Why
buildKeys.mtshas been dead code since the ts-morph migration (606ec44). Nothing undersrc/imports it and it is not re-exported fromsrc/tsmorph/index.mts, so it was unreachable through any declared package export —package.jsonmaps the package root only todist/generate.mjs. (It was still compiled and published, sincefiles: ["dist"]ships the whole output directory.) Its only consumer was its own test file.More importantly it is actively misleading. It emits a naming scheme the generator does not produce:
buildKeys.mts(deleted)findPetsQueryKeyuseFindPetsKeyFindPetsQueryKeyFnUseFindPetsKeyFnUseFindPaginatedPetsInfiniteKeyFnQuery keys are really built by
buildQueryKeyConst,buildMutationKeyConst,buildQueryKeyFn,buildMutationKeyFn,buildInfiniteQueryKeyConstandbuildInfiniteQueryKeyFninsrc/tsmorph/buildCommon.mts, called fromgenerateFiles.mts. Anyone readingbuildKeys.mtsto understand key generation is led to the wrong conclusion.Why the added tests
The deleted module was at 100% coverage (18 lines / 8 functions / 8 branches), so removing it takes well-covered lines out of the denominator and lowers the aggregate:
Rather than lower the threshold, this covers two genuinely untested paths in
buildGenerationContext— the missing-service-filethrowand the missing-models-file[]fallback.parseOperations.mtsbranch coverage goes from 76% to 80%.The missing-models fallback matters downstream: empty
modelNamessuppresses thetypes.genimport in every generated file (src/tsmorph/projectFactory.mts:103). It is also unreachable through real hey-api output —types.genis always emitted, with per-operationData/Responsetypes, even for a spec that declares nocomponents.schemas— so a hand-built project is the only way to reach it.Verification
tsc -p tsconfig.jsonclean; biome cleanbuildKeystests, +2 added)examples/react-app/openapi(26 files) built from the pre-deletiondist, regenerated with the post-deletiondist,diff -rshows no differenceNotes for the reviewer
Two follow-ups found while doing this, deliberately left out of scope:
src/tsmorph/generateFiles.mts:48-76is a verbatim private copy of the exported, already-testedbuildCommonFileImports/buildHookFileImportsinprojectFactory.mts:143-171, and threeif (hook)guards there are unreachable (the call sites pre-filter onisPaginatable, and the builders returnnullonly when!isPaginatable). Fixing both would raise that file's 68.75% branch coverage by removing branches rather than adding tests — and would unblock switching tocoverage.thresholds.perFile, which a global aggregate can't safely express today.tests/inputs/no-models.yamlis orphaned and broken: its only consumer was deleted in 606ec44, and it was alreadytest.skipped before that due to an upstream@hey-api/openapi-tserror.