Skip to content

feat(enrichment): add unsafe-any TypeScript counter analyzer - #3339

Closed
jaso0n0818 wants to merge 1 commit into
JSONbored:mainfrom
jaso0n0818:feat/unsafe-any-analyzer-2017
Closed

feat(enrichment): add unsafe-any TypeScript counter analyzer#3339
jaso0n0818 wants to merge 1 commit into
JSONbored:mainfrom
jaso0n0818:feat/unsafe-any-analyzer-2017

Conversation

@jaso0n0818

Copy link
Copy Markdown
Contributor

Closes #2017

What

A new local REES analyzer, unsafeAny, that counts and locates explicit any usage a PR ADDS in TypeScript — a : any annotation, an as any cast, or an <any> assertion/type-argument. A type-safety-erosion signal a reviewer can weigh. Structural regex only (no type-checker), pure, no network.

Detection

  • TS-gated: only .ts/.tsx/.mts/.cts files are scanned, so JS or prose can't false-positive on the word any.
  • Three kinds, each matched with \bany\b so anyOf/anything/Company never match:
    • annotation: any
    • castas any
    • assertion — an explicit any inside an angle-bracket type-argument / assertion list, not only the bare <any>: Record<string, any>, Map<string, any>, Promise<any[]>, and Array<any> are all surfaced (a nested generic matches on its innermost <…> group)
  • Cheap best-effort string/comment avoidance (per the issue's "ignoring occurrences inside string/comment where cheaply detectable"): string literals are blanked via secret-log.ts's codeOnly, same-line /* */ and trailing // comments are stripped, and a JSDoc/comment continuation line is skipped — but ONLY the * /bare-*/*/ continuation shapes, not a generator method like *load(): any {} whose * is followed by an identifier (its : any is still counted). So "cast as any" in a string, // treat as any value, and * @param p : any are not counted, while const v: any = load(); // TODO still is. Known limitation (documented in the source, not claimed as a guarantee): cross-line block-comment state is not tracked, so an any on a continuation line of a multi-line /* … */ comment that does not begin with * can still be counted — a rare, accepted false positive of the cheap-strip approach the issue explicitly scopes to "where cheaply detectable".
  • Kinds are de-duplicated per line; added lines only, line-cited via hunk headers, with the shared \ No newline line-counter fix; findings capped (maxFindings: 25) per file and globally.

Registration

Registered as a local descriptor (category quality, cost local, requires ["files"]) with an inline render(), following the redos/todoMarker descriptor shape. All wiring updated: types.ts (UnsafeAnyFinding + unsafeAny? key), render.ts, analyzer-registry.test.ts, root src/review/enrichment-analyzer-names.ts, root test/unit/enrichment-wire.test.ts, and the generated analyzer-metadata.json / rees-analyzers.ts / .env.example via node scripts/generate-analyzer-metadata.mjs.

Tests

review-enrichment/test/unsafe-any.test.ts (13 tests) covers: annotation vs cast vs assertion (including Array<any>), any inside multi-argument / compound / nested generic type arguments (Record<string, any>, Promise<any[]>, Map<string, any>, Map<K, Set<any>>) surfaced as assertions while a no-any generic (Record<string, number>) is not, multiple distinct kinds on one line de-duplicated, word-boundary rejection (anyOf/anything/Company), string/line-comment/block-comment/JSDoc suppression, a real annotation with a trailing comment still counted, non-TS files skipped (.js/.md), added-line scanning with exact locations, added-lines-only with line-number accuracy across mixed hunks, the per-file cap + maxFindings: 0, the entrypoint's TS-only gating + global cap across files, the no-files case, and the rendered brief section. Analyzer metadata is regenerated and committed.

@jaso0n0818
jaso0n0818 requested a review from JSONbored as a code owner July 5, 2026 04:06
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.88%. Comparing base (01e96c6) to head (3b3acac).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3339   +/-   ##
=======================================
  Coverage   93.88%   93.88%           
=======================================
  Files         280      280           
  Lines       30534    30534           
  Branches    11120    11120           
=======================================
  Hits        28666    28666           
  Misses       1211     1211           
  Partials      657      657           
Files with missing lines Coverage Δ
src/review/enrichment-analyzer-names.ts 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 5, 2026
@loopover-orb

loopover-orb Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Important

🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪🟪

🔍 Gittensory is reviewing…

AI analysis is in progress. This comment will update when the review is complete.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed · 🟪 Reviewing

@JSONbored JSONbored left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge conflicts:

This branch has conflicts that must be resolved
Use the [web editor](https://github.com/JSONbored/gittensory/pull/3339/conflicts) or the command line to resolve conflicts before continuing.

.env.example
apps/gittensory-ui/src/lib/rees-analyzers.ts
review-enrichment/analyzer-metadata.json
review-enrichment/src/analyzers/registry.ts
review-enrichment/src/render.ts
review-enrichment/src/types.ts
review-enrichment/test/analyzer-registry.test.ts
src/review/enrichment-analyzer-names.ts
test/unit/enrichment-wire.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. manual-review Gittensor contributor context

Development

Successfully merging this pull request may close these issues.

feat(enrichment): unsafe-any (TS) counter analyzer

2 participants