Skip to content

fix(npm): lint and format the whole source tree, not one file - #75

Merged
c-vigo merged 4 commits into
devfrom
bugfix/66-lint-format-globs
Jul 14, 2026
Merged

c-vigo merged 4 commits into
devfrom
bugfix/66-lint-format-globs

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #66.

npm run lint and npm run format have never checked the real source. Both globbed with src/**/*.ts, but npm runs scripts through sh, which has no globstar — so ** degrades to a single * and the pattern collapses to src/*/*.ts, matching only files exactly one directory deep. In practice: one test-setup file. commit.ts, commit-runner.ts and retry.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.ts rethrew a git status failure without attaching the original error, discarding the underlying execSync cause (preserve-caught-error).
  • isBinaryFromStat initialised bytesRead to 0 and 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 because format never 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-managed ci.yml has a "Lint & Format" job, but it runs just 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-quality workflow (a separate file, since ci.yml is managed and must not be edited — the same arrangement dist-check.yml uses). It runs just lint and a new read-only just format-check recipe, 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-imports findings and planned a src/__tests__ rule override for them. Both are now moot: the ESM migration (#58) removed require() 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, executing eslint src and prettier --check src for real (All matched files use Prettier code style!), not vacuously.
  • E2E Smoke passed, 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

c-vigo added 4 commits July 14, 2026 16:33
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
@c-vigo
c-vigo merged commit ca8afa7 into dev Jul 14, 2026
12 checks passed
@c-vigo
c-vigo deleted the bugfix/66-lint-format-globs branch July 14, 2026 14:58
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