-
Notifications
You must be signed in to change notification settings - Fork 38
chore(checks): wire custom checks into pre-push + CI, add no-duplicate-guards #2311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,9 +5,12 @@ | |||||
| // Runs the following checks in parallel and prints a unified summary table: | ||||||
| // - scripts/lint/no-raw-regex.ts | ||||||
| // - scripts/lint/no-raw-typeof.ts | ||||||
| // - scripts/lint/no-raw-process-env.ts | ||||||
|
||||||
| // - scripts/lint/no-raw-process-env.ts | |
| // - packages/env/scripts/no-raw-process-env.ts |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,184 @@ | ||||||
| #!/usr/bin/env bun | ||||||
| // | ||||||
| // no-duplicate-guards.ts — flags re-implementations of guards that are already | ||||||
| // exported from @packrat/guards. | ||||||
| // | ||||||
| // The guards package (packages/guards/) is the single source of truth for all | ||||||
| // type narrowing and assertion helpers. Duplicating them in app code leads to | ||||||
| // subtle behavioural divergence and breaks the "use guards, not casts" policy. | ||||||
| // | ||||||
| // Flags: | ||||||
| // - assertDefined / assertNonNull / assertPresent / assertIsString / | ||||||
| // assertIsNumber / assertIsBoolean / assertAllDefined | ||||||
| // - isString / isNumber / isBoolean / isFunction / isArray / isObject / | ||||||
| // isDate / isDefined / isPresent (re-implementations, not re-exports) | ||||||
| // - makeEnumGuard / makeTypeGuard / assertError / assertNever | ||||||
| // | ||||||
| // A "re-implementation" is any function declaration or arrow-function | ||||||
| // assignment whose name matches one of the guard names above, found outside | ||||||
| // packages/guards/ and packages/checks/ (the check scripts themselves). | ||||||
| // | ||||||
| // Exit code: | ||||||
| // 0 — no violations | ||||||
| // 1 — violations found | ||||||
| // | ||||||
| // Wired into check-all.ts and CI via checks.yml. | ||||||
|
||||||
| // Wired into check-all.ts and CI via checks.yml. | |
| // Wired into check-all.ts. |
Copilot
AI
Apr 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXCLUDED_PREFIXES values include a trailing /, but walkDir builds relPath values like packages/guards (no trailing slash) for the directory itself. As a result, isExcluded('packages/guards') returns false and this script will scan the canonical implementations in packages/guards/ (and packages/checks/), causing self-violations and making the check fail on every run. Consider normalizing relPath (e.g., ensure it always ends with / when comparing) or updating isExcluded to treat both exact directory matches and prefix matches as excluded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI adds a
lint:customstep, but it currently runs onlyno-raw-typeof,no-raw-regex, andno-raw-process-env(perpackage.json). The newly addedno-duplicate-guardscheck is not executed anywhere in CI, so duplicates can still land by bypassing local hooks. Consider runningbun check:all(optionally withcontinue-on-errorwhile backlog is cleared) or addingno-duplicate-guardstolint:custom/ as its own step.