Repository navigation
Add code quality lint for type assertions - #19462
Conversation
Enforce type assertion style by adding a new oxlint scan with `typescript/consistent-type-assertions` rule. Requires using `as const`, type annotations, or `satisfies` instead of raw type casts, with documented `SAFETY:` exceptions for unavoidable cases.
📝 WalkthroughWalkthroughThe change adds guidance to avoid TypeScript type assertions except Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to The new casting-policy gate can accept undocumented exceptions and can impose casting requirements on unrelated suppressions. Fix these parsing gaps before relying on the check to enforce the documented policy. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, solution, testing, and scope, but it omits several required template sections. It does not include ELI5, What Changed, Why, a Linked Issue, Visual Proof with the required N/A wording, Review, Agent skill upstream boundary, or Notes.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: cd291006-f0e5-422e-bfcc-677085150287
📒 Files selected for processing (4)
AGENTS.mdconfig/oxlint-code-quality-casting.jsonconfig/scripts/casting-code-quality.test.mjsconfig/scripts/check-changed-code-quality.mjs
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
There was a problem hiding this comment.
Important
The documented SAFETY: escape hatch for unavoidable casts itself fails the changed-code-quality gate, so any PR that legitimately needs a cast would be blocked from merging. Details inline.
Reviewed changes
- New
casting code qualityoxlint scan — addsconfig/oxlint-code-quality-casting.json(typescript/consistent-type-assertionswithassertionStyle: "never") and registers it as a fourth scan incheck-changed-code-quality.mjs, gated to added lines like the existing scans. - AGENTS.md guidance — documents "avoid type assertions except
as const" and the// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: ...exception syntax. - Test coverage —
casting-code-quality.test.mjsverifies the scan flags unsafe casts (as string | null,as unknown as string,<string>), allowsas const/satisfies/ annotations, and respects theSAFETY:disable directive.
Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:
config/scripts/casting-code-quality.test.mjs:92(RIGHT) — line 92 (RIGHT) is not inside a diff hunk
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: c220cc78-7465-4405-9b8f-afa81e1e2f66
📒 Files selected for processing (2)
config/scripts/casting-code-quality.test.mjsconfig/scripts/check-changed-code-quality.mjs
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — one minor suggestion inline.
Reviewed changes
Re-reviewed the fix commit 6c11da5 against the prior pullfrog review. The prior blocker (the documented SAFETY: escape hatch failing the gate) is resolved and I verified it end-to-end; one minor observation remains.
- Exempted casting directives from unused-directive warnings —
isCastingDirectiveUnusedWarningfilters thecode qualityscan's unused-directive warning for directives namingtypescript/consistent-type-assertions, so aSAFETY:suppression no longer fails the gate. - Enforced the
SAFETY:rationale —findCastingDirectivesMissingSafetyflags added/changed lines carrying a casting suppression without aSAFETY:explanation, reported and counted bymain(). - Added tests — cover the unused-directive exemption, missing-rationale rejection, gating to added lines, and a trailing
oxlint-disable-lineabutting a string literal.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
The fabricated-Dirent readdir mock could not satisfy both gates at once: vi.mocked(readdirSync) resolves to Node's Dirent<NonSharedBuffer> overload, so the mock needed a type assertion, and #19462's casting gate rejects new ones on changed lines. Removing the cast then failed tsc. Extract directoryEntryNeedsStat and test it directly with a structural probe. No mock, no cast, no top-level await, and the DT_UNKNOWN case is pinned: removing the fallback fails 'stats an entry whose type readdir could not report'.
* perf(tooling): reuse directory entry types in source scans
* fix(source-scan): stat DT_UNKNOWN dirents so untyped directories are still walked
`readdirSync(..., { withFileTypes: true })` can hand back a Dirent whose
type the filesystem did not report. For that entry every predicate is
false, so the readdir-type fast path treated a real directory as a file
and silently dropped its subtree from every ratchet guard. Fall back to
`statSync` whenever the entry is neither conclusively a file nor a
directory, keeping the no-stat fast path for ordinary entries.
Also make the two readdir-order assertions in the walk test
order-independent; `scanSourceTree` returns raw readdir order, which
differs on tmpfs.
* test(source-scan): unit-test the stat fallback via an extracted helper
The fabricated-Dirent readdir mock could not satisfy both gates at once:
vi.mocked(readdirSync) resolves to Node's Dirent<NonSharedBuffer> overload, so
the mock needed a type assertion, and #19462's casting gate rejects new ones on
changed lines. Removing the cast then failed tsc.
Extract directoryEntryNeedsStat and test it directly with a structural probe.
No mock, no cast, no top-level await, and the DT_UNKNOWN case is pinned:
removing the fallback fails 'stats an entry whose type readdir could not report'.
---------
Co-authored-by: m4air <m4air@Mac.localdomain>
Co-authored-by: Neil <neil@stably.ai>

Problem
The codebase needs automated enforcement of safe type assertion patterns. Without it, developers can accidentally use unsafe casts that hide type issues.
Solution
Added a dedicated oxlint scan that enforces the
typescript/consistent-type-assertionsrule set toneverstyle. This prevents unsafe casts while allowing documented exceptions withSAFETY:comments andas constpatterns. Includes:config/oxlint-code-quality-casting.json) targeting just the casting ruleAGENTS.mdexplaining the pattern and exception syntaxThe scan integrates with the existing changed-code-quality check and only flags new or modified lines.
Testing
config/scripts/casting-code-quality.test.mjsthat verifies:as string | null,as unknown as string,<string>) are caughtas const, type annotations,satisfies) passSAFETY:comments are respectedChecklist
pnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (CI will cover)