Skip to content

refactor(review-enrichment): dedupe REES analyzer limit magic numbers into shared constants #4163

Description

@JSONbored

Context

Follow-up to #1477 (merged via #4155). The gittensory-orb review on that PR flagged, as non-blocking nits:

The magic numbers 25/2000/10 are duplicated as literals across registry.ts, rees-analyzers.ts, and analyzer-metadata.json ... worth a shared constant given how many copies now exist.

Consider factoring the 25/2000/10 literals into named exported constants imported by all four registration sites, since this PR is the third analyzer to duplicate the same numbers verbatim.

The same review also separately noted:

review-enrichment/src/analyzers/complexity.ts and error-swallow.ts themselves trip the repo's own deep-nesting threshold (depth 5 vs. 4) per the external brief — worth a quick refactor of the nested pending/flush logic for consistency with what the analyzer polices elsewhere.

Scope

  1. Create review-enrichment/src/analyzers/limits.ts exporting DEFAULT_MAX_FINDINGS = 25 / DEFAULT_MAX_LINE_CHARS = 2000. Tracing the codebase found this pair duplicated as a raw literal across 28 analyzer files (MAX_FINDINGS = 25) and 18 (MAX_LINE_CHARS = 2000), plus registry.ts's 50 descriptor limits: {...} objects (28 maxFindings: 25 / 18 maxLineChars: 2000 occurrences) — far more than the "third analyzer" the review's own diff view could see. Analyzer-specific overrides (asset-weight's 50, heavy-dependency's 15, migration-safety/loose-range's 20, undocumented-export/provenance's 30) are NOT touched — those are real per-analyzer tuning, not duplicate-worth-fixing.
  2. maxDepth: 4 (deep-nesting.ts's own DEFAULT_MAX_DEPTH) and maxComplexity: 10 (complexity.ts's own DEFAULT_MAX_COMPLEXITY) were also duplicated as raw literals in their registry.ts descriptors — import each analyzer's own existing exported constant into registry.ts instead of repeating the literal.
  3. Regenerate review-enrichment/analyzer-metadata.json + apps/gittensory-ui/src/lib/rees-analyzers.ts + the .env.example generated block via npm run rees:metadata (confirmed byte-identical, since only the source's use of named constants changed, not the underlying values).
  4. Extract complexity.ts's and error-swallow.ts's innermost pending/flush conditional into named helper functions, empirically verified (via the sibling deep-nesting.ts analyzer's own exported scanPatchForDeepNesting, fed each file's actual diff) to bring both from depth 5 down to under the repo's own depth-4 policy.

Acceptance criteria

  • No analyzer file, or registry.ts descriptor, repeats the literal 25/2000 where the shared default applies; genuinely different per-analyzer values are left untouched.
  • complexity.ts and error-swallow.ts's own diffs no longer trip scanPatchForDeepNesting's depth-4 threshold.
  • review-enrichment's own npm test (build + sourcemap validation + metadata --check + full test suite) stays green; behavior is unchanged (same test assertions pass before and after).

Ownership

Maintainer-only, review-enrichment/-scoped. Not Codecov-measured (review-enrichment/** is outside src/**/packages/**).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Status
Done

Relationships

None yet

Development

No branches or pull requests

Issue actions