You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Summary
This PR retunes the next batch of CodeGuard precision false positives
from TypeScript/JavaScript API and integration code. The goal is to keep
the production-readiness checks useful while avoiding noisy findings for
patterns that are already bounded, typed, or intentionally surfaced to
callers.
### What changed
- Retuned `defensive.integer-overflow`.
- Stops treating `count + 1` external ID allocation as numeric overflow.
- Skips seed/script paths and date/count formatting arithmetic.
- Keeps actual unsafe size arithmetic covered.
- Refined `defensive.sequence-collision-risk`.
- `count + 1` external ID allocation is now reported under
sequence-collision risk instead of integer overflow.
- Bounded Prisma `P2002` / unique-collision retry is treated as
mitigation, not full resolution.
- Retry-mitigated cases emit a lower-confidence architectural-debt
warning recommending a database sequence, UUID, or transactional
allocator.
- Retuned `defensive.bounds-assumption`.
- Narrows the rule to sequence-like indexing.
- Avoids dictionary/object/env access such as `fieldMap[name]` and
`process.env[name]`.
- Retuned `defensive.missing-resource-limit`.
- Credits Prisma `take`.
- Credits bounded constants and pre-`formData()` content-length helper
guards.
- Keeps truly unbounded request/form reads covered.
- Retuned `function.inconsistent-return-contract`.
- Allows parser, lookup, read, resolve, and extraction helpers with
explicit nullable contracts such as `T | null`.
- Allows `exists()` true/false contracts.
- Corrects `return false` so it is no longer treated as an empty return.
- Retuned `error.partial-failure-hidden`.
- Allows digest/fetch loops that append diagnostics/errors/failures and
return those diagnostics to callers.
- Keeps silent `catch`/`continue` paths covered.
- Updated user-facing metadata.
- Updated rule catalog, fix-template guidance, and `docs/checks.md` for
the retry-mitigated sequence-debt behavior.
### Tests
- Added regression coverage for retry-wrapped external ID allocation.
- Added regression coverage for seed/script and date bucket arithmetic.
- Added regression coverage for dictionary/env indexing vs array
indexing.
- Added regression coverage for Prisma `take` and pre-`formData()`
content-length helper guards.
- Added regression coverage for nullable parser/lookup/exists return
contracts.
- Added regression coverage for surfaced diagnostics vs hidden partial
failures.
## Validation
- Focused regression tests
- `go test ./tests/checks -count=1`
- `go test ./...`
- `golangci-lint run`
- `make codeguard-ci`
Copy file name to clipboardExpand all lines: docs/checks.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1186,7 +1186,7 @@ These rules live outside the repository-wide `Change Safety` section in report o
1186
1186
| Defensive programming | `defensive.invalid-state-representable` | warn | Booleans or raw status strings can represent impossible state combinations. |
1187
1187
| Defensive programming | `defensive.null-assumption` | warn | Nullable boundary values are dereferenced without a nil/null guard. |
1188
1188
| Defensive programming | `defensive.integer-overflow` | warn | Arithmetic on count, size, or length input lacks an overflow bound check. |
1189
-
| Defensive programming | `defensive.sequence-collision-risk` | warn | External ID allocation derives the next value from current count without guarded unique-collision retry. |
1189
+
| Defensive programming | `defensive.sequence-collision-risk` | warn | External ID allocation derives the next value from current count; bounded unique-collision retry is treated as mitigation, not full resolution. |
1190
1190
| Defensive programming | `defensive.bounds-assumption` | warn | Indexed access assumes collection bounds without a nearby length check. |
1191
1191
| Defensive programming | `defensive.unsafe-default` | warn | A config/env fallback can fail open or disable a safety control. |
1192
1192
| Defensive programming | `defensive.non-exhaustive-branch` | warn | Enum-like state/kind/type branching lacks default or exhaustive handling. |
"external ID allocation is protected by bounded unique-collision retry, but count-derived IDs remain architectural debt; prefer a database sequence or transactional allocator",
260
+
core.ConfidenceLow,
261
+
true
254
262
}
255
-
returnfirstSequenceAllocationLine(fn), true
263
+
returnline,
264
+
"external ID allocation derives the next value from current count; use a database sequence, UUID, or transactional allocator instead of count-based generation",
Copy file name to clipboardExpand all lines: internal/codeguard/rules/catalog_fix_templates_quality_errors_defensive.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ var qualityErrorDefensiveFixTemplates = map[string]core.FixTemplate{
18
18
"defensive.invalid-state-representable": {Kind: guided, Text: "Replace boolean combinations/raw strings with an enum, tagged union, or state machine that encodes valid states."},
19
19
"defensive.null-assumption": {Kind: guided, Text: "Guard nil/null/None/optional values before dereference, or make the boundary type non-nullable."},
20
20
"defensive.integer-overflow": {Kind: guided, Text: "Guard count/size arithmetic before multiplication, addition, shifts, or allocation sizing."},
21
-
"defensive.sequence-collision-risk": {Kind: guided, Text: "Replace count-plus-one external IDs with database sequences/UUIDs, or wrap allocation in a bounded unique-collision retry."},
21
+
"defensive.sequence-collision-risk": {Kind: guided, Text: "Replace count-plus-one external IDs with database sequences, UUIDs, or a transactional allocator. A bounded P2002/unique-collision retry mitigates collisions but should still be treated as architecture debt."},
22
22
"defensive.bounds-assumption": {Kind: guided, Text: "Check length/existence before indexing, or use a safe lookup API."},
23
23
"defensive.unsafe-default": {Kind: guided, Text: "Make security/safety defaults fail closed and require explicit opt-out for unsafe behavior."},
24
24
"defensive.non-exhaustive-branch": {Kind: guided, Text: "Add an explicit default/unreachable branch or exhaustive assertion for enum-like state switches."},
0 commit comments