Skip to content

fix: retune precision false positives - #81

Merged
alxxjohn merged 3 commits into
mainfrom
fix/precision-retune-builders-boundaries
Jul 28, 2026
Merged

fix: retune precision false positives#81
alxxjohn merged 3 commits into
mainfrom
fix/precision-retune-builders-boundaries

Conversation

@alxxjohn

Copy link
Copy Markdown
Contributor

Summary

This PR retunes CodeGuard's local quality precision checks to reduce high-volume false positives from common TypeScript/JavaScript, React, Next.js, and API-boundary patterns while preserving the intended production-readiness signals.

What changed

  • Hardened function.hidden-mutation so local scratch mutation in pure builders/parsers is not treated as hidden mutation.

    • Allows local Set.add, Map.set, array.push, .sort, .split().pop(), object accumulation, and Cheerio cleanup when the function returns a derived value.
    • Keeps the rule focused on mutation of arguments, module/global state, collaborators, React state, DOM, DB, filesystem, or other external resources.
  • Retuned function.command-query-mix for query-safe builder/parser patterns.

    • Pure builders/parsers that mutate local scratch state no longer look like command/query violations.
    • Command functions that intentionally write and return useful results are treated as normal API/application behavior.
  • Improved boundary/resource validation recognition.

    • Credits z.safeParse, helper-returned validated values, NextResponse early-return guards, new URL(...) plus protocol allowlists, shared upload validators, and imported byte-limit constants.
    • Credits Content-Length preflight, explicit take/limit, slice, count/size/byte guards, and bounded response byte-length checks for defensive.missing-resource-limit.
  • Split sequence-allocation risk from arithmetic overflow.

    • Added defensive.sequence-collision-risk for count-derived external ID allocation without guarded unique-collision retry.
    • Keeps guarded Prisma/P2002 retry loops out of defensive.integer-overflow.
    • Suppresses metric/stat arithmetic from overflow findings.
  • Reduced naming and smell noise.

    • Allows common UI boolean/domain names such as show*, matches*, visible, active, open, selected, enabled.
    • Allows collection/domain abbreviations such as krs, docs, and ids.
    • Tolerates centralized enum/domain dispatch maps for smell.switch-on-type.
  • Added rule metadata and documentation.

    • Registered defensive.sequence-collision-risk in the rule catalog and fix-template catalog.
    • Updated docs/checks.md so users can discover the new defensive rule.

Tests

  • Added regression coverage for local builder/parser mutation patterns.
  • Added regression coverage for boundary validation and resource-limit proof patterns.
  • Added regression coverage for sequence-collision vs integer-overflow behavior.
  • Updated existing UI false-positive hardening tests to match the narrower analyzer behavior.

Validation

  • go test ./tests/checks -run 'TestDefensive(Integer|Resource)|TestRulesCatalog' -count=1
  • go test ./tests/checks -count=1
  • go test ./...
  • golangci-lint run
  • make codeguard-ci

@alxxjohn
alxxjohn merged commit a63ff23 into main Jul 28, 2026
16 checks passed
@alxxjohn
alxxjohn deleted the fix/precision-retune-builders-boundaries branch July 28, 2026 15:21
alxxjohn added a commit that referenced this pull request Jul 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.3.5](v1.3.4...v1.3.5)
(2026-07-28)


### Bug Fixes

* cover remaining precision retunes
([1fd6f2b](1fd6f2b))
* retune precision false positives
([6a09863](6a09863))
* retune precision false positives
([#81](#81))
([a63ff23](a63ff23))
* split defensive sequence collision signal
([c734e9a](c734e9a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant