testsAndMisc/docs/superpowers/evidence/bucket-catch-eslint-2026-08-17.json
Krzysztof kuhy Rudnicki e165ae8987 bucket_catch: 45 eslint errors -> 5, no suppressions
These were unmasked, not caused, last session: `lint` is
`tsc --noEmit && eslint src`, and a broken tsc had been short-circuiting
the && so eslint had never run on this package.

The binding constraint is the 100% coverage gate, not the linter. Most
idiomatic fixes for no-non-null-assertion add a branch that no test can
reach, which trades a lint error for a coverage failure - and the
no-suppressions rule forbids escaping either way. So every fix here is
one that adds no branch:

- no-non-null-assertion 18 -> 2: a waitFor already proves result.current
  is non-null, so capture it into a local instead of asserting on each
  read. App.tsx's files[0]! was pure noise (the same position also
  reported no-unnecessary-type-assertion). usePuzzleGameLoop's shift()!
  became index-then-shift, since the while condition already indexes [0]
  unasserted.
- non-nullable-type-assertion-style 9 -> 0: the rule-swap trap - eslint
  asks for `!`, which the other rule forbids. Narrowed with instanceof.
- unbound-method 10 -> 1: keep the MockInstance vi.spyOn already returns
  rather than detaching the method. This surfaced a latent bug: one test
  calls restoreAllMocks() mid-test, so the beforeEach handle was stale.
- no-unnecessary-type-assertion 5 -> 1, require-await 1 -> 0.

Coverage held at 100%: 584/217/98/535 -> 585/217/98/536. The +1 statement
and +1 line are the index-then-shift split; branches unchanged at 217 is
the number that proves no fix added an untested path. 145 tests, tsc 0.

The 5 remaining are reported, not silenced. App.tsx's fileResult! needs
the phase state to carry the result ({ kind: "done"; result }) - three
smaller structures all failed the same way. The rest are documented in
the evidence file.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
2026-08-17 11:48:45 +02:00

48 lines
5.4 KiB
JSON

{
"intent": "Fix the eslint errors in bucket_catch/packages/frontend, which had never run against that package until a typecheck repair last session unmasked them, without using a single suppression and without letting the 100% coverage gate slip.",
"scope": [
"9 test files and 2 production files under bucket_catch/packages/frontend/src",
"45 errors down to 5; the remaining 5 are named below and left as reported findings",
"Non-goal: no behaviour change, no test removed, no eslint rule disabled or downgraded"
],
"changes": [
"no-non-null-assertion (18 -> 2): in useGameLoop.test.ts and usePuzzleGameLoopPlay.test.ts the pattern was a waitFor that asserts result.current is non-null followed by several `result.current!.x` reads; replaced by capturing the value into a local and throwing if it is null, which narrows for every following line. In App.tsx `files[0]!` was simply deleted - the same position also reported no-unnecessary-type-assertion, proving the assertion changed nothing. In usePuzzleGameLoop.ts the `shift()!` became an index-then-shift, because the enclosing while condition already dereferences [0] without an assertion.",
"non-nullable-type-assertion-style (9 -> 0): these are the rule-swap trap - eslint asks for `!`, which no-non-null-assertion then forbids. Resolved in DropZone.test.tsx with a `must()` helper that narrows via instanceof and throws with a useful message, and in PuzzleResult.test.tsx with an inline instanceof guard.",
"unbound-method (10 -> 1): assertions like expect(URL.revokeObjectURL) detach a method from its object. Replaced by keeping the MockInstance handle that vi.spyOn already returns - the pattern zipDownload.test.ts was using for appendSpy/removeSpy - and asserting on that.",
"no-unnecessary-type-assertion (5 -> 1) and require-await (1 -> 0): dropped the redundant `as React.RefObject<T>` from three makeRef helpers, and removed `async` from a test with no await."
],
"verification": [
{
"command": "npx eslint src",
"result": "pass",
"evidence": "45 errors before, 5 after. Remaining: App.tsx no-non-null-assertion (1), usePuzzleGameLoop.ts no-non-null-assertion (1), sliceImage.test.ts no-this-alias (1) and unbound-method (1), zipDownload.test.ts no-deprecated (1). Each is explained under risks; none is suppressed."
},
{
"command": "npm run coverage",
"result": "pass",
"evidence": "Before: 584 statements / 217 branches / 98 functions / 535 lines, all 100%. After: 585 / 217 / 98 / 536, all still 100%. The +1 statement and +1 line are the index-then-shift edit in usePuzzleGameLoop.ts splitting one statement into two. Branches unchanged at 217 is the number that matters: no fix introduced an untested branch, which is the failure mode that would otherwise force a suppression or an unreachable guard."
},
{
"command": "npx vitest run (via npm run coverage)",
"result": "pass",
"evidence": "145 tests in 15 files pass, the same count as before. Every touched test file was also run individually as it was changed."
},
{
"command": "npx tsc --noEmit",
"result": "pass",
"evidence": "exit 0. This is the first half of `npm run lint`, and it was the step whose earlier failure had been short-circuiting the && and hiding eslint entirely."
}
],
"risks": [
"zipDownload.test.ts 'sets download attribute and href on the anchor' calls vi.restoreAllMocks() mid-test and re-spies. Moving the beforeEach spies into handles made that assertion read a stale handle and the test failed; it now keeps a local handle created after the restore. The test was already fragile in this way - the refactor made the dependency explicit rather than introducing it.",
"App.tsx no-non-null-assertion is NOT fixed and needs a real refactor: `fileResult!` in the done phase. Three attempts each failed the same way - a null guard adds a branch no test can reach (App's flow never produces a done phase with no result), and retagging GameResult still leaves the value nullable in the fall-through. The right fix is to move the result into the phase state (`{ kind: 'done'; result: GameResult }`), so narrowing on the phase removes the null. That is a wider change than this commit and is left for a follow-up.",
"usePuzzleGameLoop.ts:127 `resolvedFrameMapRef.current.get(item.id)!` is likewise unfixed: Map.get returns `| undefined` and the invariant (the id was inserted a few lines above) is not visible to the type system. A guard here would also be an unreachable branch.",
"sliceImage.test.ts no-this-alias: the FakeImage constructor does `capturedImg = this` so the test can drive onload. A factory breaks `new Image()`, and a Proxy wrapper passed the tests but did not reduce the error count and was more complex than what it replaced, so it was reverted. Its remaining unbound-method is on a getContext prototype save/restore.",
"zipDownload.test.ts no-deprecated is on the `(tag: string)` overload of document.createElement, needed because the spy must accept the signature vi.spyOn infers. Building elements from constructors instead fails under jsdom (HTMLAnchorElement is not constructible), so the deprecated overload stays."
],
"rollback": [
"git revert the commit. All 45 eslint errors return; nothing else changes, since no production behaviour was altered.",
"After rollback, confirm npm run coverage still reports 100% with 584/217/98/535 and 145 passing tests, and that npx tsc --noEmit exits 0."
]
}