chore(hygiene): add structural lint enforcement script and noConsole rule#4627
chore(hygiene): add structural lint enforcement script and noConsole rule#4627waleedlatif1 wants to merge 4 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryLow Risk Overview Tightens Biome linting by making Reviewed by Cursor Bugbot for commit 3193cac. Configure here. |
Greptile SummaryThis PR introduces structural hygiene enforcement: a new
Confidence Score: 3/5The route fix and most suppressions are correct, but the misaligned suppression comment in stream.test.ts means the hygiene script would still report a violation on that file rather than passing clean as claimed. The hygiene-suppress comment in stream.test.ts sits before vi.mock (line 14), but vi.importActual is on line 16. Because isSuppressed only looks one line back, the script evaluates the vi.mock line as the predecessor and emits the violation, contradicting the PR claim that check:hygiene passes clean. apps/sim/lib/copilot/request/go/stream.test.ts — the hygiene-suppress comment needs to move inside the vi.mock callback, directly above the vi.importActual call. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[bun run check:hygiene] --> B[checkTsIgnore]
A --> C[checkBareRoutes]
A --> D[checkVitestAntiPatterns]
B --> B1[Scan apps and packages ts/tsx files]
C --> C1[Scan apps/sim/app/api route.ts files]
D --> D1[Scan apps and packages test.ts files]
B1 --> SUP{isSuppressed - lines i-1 has hygiene-suppress?}
C1 --> ALLOW{In BARE_ROUTE_ALLOWLIST?}
D1 --> SUP
ALLOW -- Yes --> SKIP[Skip]
ALLOW -- No --> SUP
SUP -- Yes --> SKIP
SUP -- No --> V[Add violation]
V --> EXIT1[process.exit 1]
SKIP --> EXIT0[process.exit 0]
Reviews (1): Last reviewed commit: "chore(hygiene): add structural lint enfo..." | Re-trigger Greptile |
| // hygiene-suppress: session re-exports many real domain functions (eventToStreamEvent, parsePersistedStreamEventEnvelope) used by stream.ts under test — must spread real implementations and override only hasAbortMarker | ||
| vi.mock('@/lib/copilot/request/session', async () => { | ||
| const actual = await vi.importActual<typeof import('@/lib/copilot/request/session')>( |
There was a problem hiding this comment.
Misaligned
hygiene-suppress comment — vi.importActual is still flagged
isSuppressed(lines, lineIndex) checks only lines[lineIndex - 1] (the line immediately before the violation). The suppression comment is on line 14 (before vi.mock), but the anti-pattern vi.importActual fires on line 16. When the checker evaluates line 16 it looks at line 15 (vi.mock(…) — which is not a suppression comment — so the violation is emitted and bun run check:hygiene would exit 1 on this file. The comment must be moved to sit directly above line 16, inside the mock callback.
There was a problem hiding this comment.
Real issue — fixed in 7663ab3. The regex now handles generics with (?:<[^>]*>)? and the suppression comment is moved inside the mock callback to sit directly above the vi.importActual call.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3193cac. Configure here.
| 'vi.resetModules() — use vi.hoisted() + vi.mock() + static imports instead (exception: singleton modules that cache state)', | ||
| }, | ||
| { | ||
| pattern: /\bvi\.importActual\s*\(/, |
There was a problem hiding this comment.
Regex misses vi.importActual with TypeScript generics
Medium Severity
The vi.importActual anti-pattern regex /\bvi\.importActual\s*\(/ requires ( to immediately follow (with optional whitespace), but the common TypeScript form vi.importActual<T>( has a generic type parameter between the method name and (. The only real-world usage in the codebase (stream.test.ts:16) uses exactly this form, so the lint rule silently misses it. Additionally, the hygiene-suppress comment in stream.test.ts is positioned to suppress line 15 (vi.mock), not line 16 where vi.importActual actually appears—so even a fixed regex would still flag it.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 3193cac. Configure here.
There was a problem hiding this comment.
Real issue — both halves fixed in 7663ab3. Regex updated to /\bvi.importActual\s*(?:<[^>]>)?\s(/ to handle TypeScript generics, and the suppression comment repositioned directly above the vi.importActual line.
…ct base64 size gate
…x suppression placement
|
Closing — the hygiene enforcement script adds more complexity than value right now. Pulling out the only real fix (MCP status codes) into a separate PR. |


Summary
scripts/check-hygiene.ts— catches three classes of violations Biome can't:@ts-ignore/@ts-expect-errorwithout explanation, bare Next.js route exports missingwithRouteHandler, and banned Vitest anti-patterns (vi.doMock,vi.resetModules,vi.importActual)check:hygieneto rootpackage.jsonscriptsnoConsoleBiome rule at error level with overrides for scripts, vitest setup files, and the hydration error handler (which intentionally patchesconsole.error)GETexport inapps/sim/app/api/copilot/chat/route.tswithwithRouteHandler; allowlist health and mothership stream routes which are intentionally barevi.importActualinroute-helpers.test.ts— replaced with explicit mock (no real module needed)// hygiene-suppresscomments to legitimatevi.resetModulesuses inredis.test.tsandisolated-vm.test.ts(both test singleton module initialization behavior)Type of Change
Testing
bun run check:hygienepasses cleanbun run check:utilspasses cleanbun run lintpasses with no errorsChecklist