Repository navigation
fix(npm): lint and format the whole source tree, not one file - #75
Merged
Merged
Conversation
npm runs scripts through sh, which has no globstar. In `eslint src/**/*.ts` the `**` degrades to a single `*`, so the pattern collapses to `src/*/*.ts` -- files exactly one directory deep. That matched a single test-setup file. src/commit.ts, src/commit-runner.ts and src/retry.ts, the entire production surface, were linted and formatted by neither script, and CI's Lint & Format job has been green on that basis since the scripts were written. Pass the directory instead and let eslint and prettier expand globs internally, with correct `**` semantics. The flat config already scopes to src/**/*.ts via its `files` key, so coverage is unchanged in intent -- only in reality. eslint now checks 6 files rather than 1. Linting the real tree surfaced two findings in production code, both fixed here; neither is a correctness bug: - commit-runner rethrew a git status failure without attaching the original error, discarding the underlying execSync cause (preserve-caught-error). - isBinaryFromStat initialized bytesRead to 0 and always overwrote it before reading (no-useless-assignment). Dropping the initializer also lets the compiler's definite-assignment analysis see the read, which it now proves. The ~25 no-require-imports findings this issue also catalogued are already gone: the ESM migration (#58) removed require() from the test suite entirely, so the planned src/__tests__ rule override is no longer needed. The whole-tree prettier reformat follows as its own commit, so it can be reviewed independently of these substantive fixes. Refs: #66
Purely mechanical; no behavior change. src/ had never been formatted, because `npm run format` globbed with src/**/*.ts and sh has no globstar, so the pattern only ever reached one file (#66, fixed in the preceding commit). This applies the repo's own checked-in .prettierrc -- singleQuote, printWidth 100 -- which the source has never matched. Most of the diff is the resulting quote flip and re-wrapping, not logic. Kept as its own commit so it can be reviewed, or dropped, independently of the substantive fixes it follows. `npx prettier --list-different src` is now empty; tsc, eslint and all 84 tests are unchanged and green. Refs: #66
Picks up the preserve-caught-error and no-useless-assignment fixes and the prettier reformat. Keeps dist/ fresh for the release-boundary gates, and for the e2e smoke job, which executes the committed bundle rather than the source. Refs: #66
Nothing enforced either tool. The scaffold-managed ci.yml has a "Lint & Format" job, but it runs `just precommit` -- the prek hook suite, which contains no JS linter or formatter. `npm run lint` and `npm run format` were only ever run by hand. That is how the broken globs survived for the life of the repo: the scripts linted one test-setup file, and nothing ever ran them to notice. Fixing the scripts without gating them would let them rot again the same way. Add a consumer-owned js-quality workflow -- a separate file, since ci.yml is managed and must not be edited, same arrangement as dist-check.yml. It runs `just lint` and a new `just format-check`, the same recipes a developer runs locally, so a green CI means a green tree rather than a CI-only invocation that can drift. format-check is the read-only counterpart of `just format`: prettier --check fails on unformatted code instead of rewriting it. Refs: #66
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.
Closes #66.
npm run lintandnpm run formathave never checked the real source. Both globbed withsrc/**/*.ts, but npm runs scripts throughsh, which has no globstar — so**degrades to a single*and the pattern collapses tosrc/*/*.ts, matching only files exactly one directory deep. In practice: one test-setup file.commit.ts,commit-runner.tsandretry.ts— the whole production surface — were matched by neither script.Fixed by passing the directory (
eslint src,prettier --write src) and letting each tool expand its own globs. eslint now checks 6 files instead of 1.Four commits, deliberately separate
1.
fix(npm)— the script fix + the two production findings. Linting the real tree surfaced two, both fixed here, neither a correctness bug:commit-runner.tsrethrew agit statusfailure without attaching the original error, discarding the underlyingexecSynccause (preserve-caught-error).isBinaryFromStatinitialisedbytesReadto0and always overwrote it before reading (no-useless-assignment). Dropping the initialiser also lets the compiler's definite-assignment analysis see the read — which it now proves, so the change is verified rather than assumed.2.
style(src)— the whole-tree prettier reformat. Mechanical, no behavior change; isolated so it can be reviewed or dropped independently.Note what it actually applies: the repo's own checked-in
.prettierrc(singleQuote: true,printWidth: 100), which the source has never matched — it's all double-quoted at ~80 cols, precisely becauseformatnever ran on it. So most of the ~609/765-line diff is the resulting quote flip and re-wrapping, not logic.3.
build(dist)— rebuild the bundle. Picks up commits 1–2. Needed because the e2e smoke job executes the committed bundle, not the source.4.
ci(lint)— gate PRs on eslint and prettier. The root cause was never just the glob: nothing ran these tools at all. The scaffold-managedci.ymlhas a "Lint & Format" job, but it runsjust precommit— the prek hook suite, which contains no JS linter or formatter. That is how the broken globs survived for the life of the repo, and fixing the scripts without a gate would let them rot again the same way.Adds a consumer-owned
js-qualityworkflow (a separate file, sinceci.ymlis managed and must not be edited — the same arrangementdist-check.ymluses). It runsjust lintand a new read-onlyjust format-checkrecipe, i.e. the same recipes a developer runs locally, so a green CI means a green tree rather than a CI-only invocation that can drift.Scope note
The issue also catalogued ~25
no-require-importsfindings and planned asrc/__tests__rule override for them. Both are now moot: the ESM migration (#58) removedrequire()from the test suite entirely. What was a 46-finding triage is down to the two above.Verification
ESLint & Prettier— the new gate ran on this PR and passed, executingeslint srcandprettier --check srcfor real (All matched files use Prettier code style!), not vacuously.E2E Smokepassed, so the rebuilt bundle still performs a genuine signed commit against the live API — the reformat and both source fixes are verified end to end, not on faith.npm test— 84/84 passing.npx tsc --noEmit— 0 errors.just precommit— green.Refs: #66