Skip to content

feat(enrichment): deep-nesting / arrow-anti-pattern heuristic analyzer - #3536

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bohdansolovie:feat/enrichment-deep-nesting-2030-v2
Jul 5, 2026
Merged

feat(enrichment): deep-nesting / arrow-anti-pattern heuristic analyzer#3536
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bohdansolovie:feat/enrichment-deep-nesting-2030-v2

Conversation

@bohdansolovie

Copy link
Copy Markdown
Contributor

Summary

Fixes #2030

  • Add DeepNestingFinding and a local deepNesting analyzer that flags newly-added control-flow blocks whose nesting depth exceeds 4 inside a contiguous run of added lines
  • Control-flow-only brace tracking: counts if/for/while/switch/try/catch/else/do/with, arrow => {, and function bodies — object-literal { braces are pushed on a stack but do not increase depth
  • Resets depth across hunk context lines; skips test paths; caps at 25 findings; clamps invalid maxDepth to the default
  • Register the analyzer in the REES registry with render/docs/metadata; sync src/review/enrichment-analyzer-names.ts and generated .env.example / UI metadata
  • Add review-enrichment/test/deep-nesting.test.ts covering deep control-flow flag, object-literal non-flag, threshold edges, context reset, cap, and brief rendering

Test plan

  • cd review-enrichment && npm run build && npm run metadata && node --test test/deep-nesting.test.ts test/analyzer-registry.test.ts
  • CI validate-code

Made with Cursor

Fixes JSONbored#2030

Co-authored-by: Cursor <cursoragent@cursor.com>
@bohdansolovie
bohdansolovie requested a review from JSONbored as a code owner July 5, 2026 16:14
@superagent-security

Copy link
Copy Markdown
Contributor

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

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 5, 2026
@loopover-orb

loopover-orb Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-05 16:20:00 UTC

10 files · 1 AI reviewer · no blockers · readiness 80/100 · CI green · clean

⏸️ Suggested Action - Manual Review

Review summary
Adds a well-structured `deepNesting` analyzer that correctly wires into the REES registry — descriptor, render hook, `BriefFindings` field, `REES_ANALYZER_NAMES`, generated metadata, and UI copy all stay in sync. Unit tests cover the core heuristic, object-literal exclusion, threshold edges, context-line resets, test-file skipping, findings cap, multi-file aggregation, and brief rendering. The control-flow brace classifier correctly distinguishes object literals from control-flow scopes in the common case. One structural limitation worth flagging: the `[^)]*` regex in `isControlFlowOpenBrace` cannot match conditions that contain a nested function call, so `if (arr.includes(x)) {` or `while (q.length() > 0) {` are silently classified as 'other' and do not increment depth — producing systematic false negatives for a very common real-world pattern.

Nits — 5 non-blocking
  • deep-nesting.ts `isControlFlowOpenBrace`: the pattern `\([^)]*\)` in the `if/for/while/switch/catch/with` branch stops at the first `)` it finds, so any condition with a nested call — `if (arr.some(x => x > 0)) {`, `if (Object.keys(obj).length > 0) {`, `for (let i = 0; i < fn(); i++) {` — hits `return false` and is tracked as depth-neutral 'other'; fix by replacing the single-group pattern with an explicit paren-depth counter loop over `before`.
  • `finally` is recognized in the first regex (`/(?:=>|\belse|\btry|\bfinally|\bdo)\s*$/`) and correctly increments depth, but every `docs.notes` string and the PR description's keyword list omits it — update all three to keep the documented keyword list consistent with the implementation.
  • The limit literals `25`, `4`, `2000` appear as bare numbers in the `registry.ts` descriptor `limits` object and in `apps/gittensory-ui/src/lib/rees-analyzers.ts`; since `DEFAULT_MAX_DEPTH`/`MAX_FINDINGS`/`MAX_LINE_CHARS` from `deep-nesting.ts` can't be imported into those files, add a short inline comment at each site noting the source constant so operators tuning `.env` overrides and future reviewers know what they're adjusting.
  • The test for context-line reset (`deep-nesting.test.ts` around line 77) constructs the inner lines without the standard single-space unified-diff context prefix (`" return x;"`), so the bare `" return x;"` line reaches the else-branch only because it doesn't start with `+` — functionally correct but slightly misleading; use `" return x;"` to match real diff output.
  • Replace the `[^)]*` single-group pattern in `isControlFlowOpenBrace` with a paren-depth scan over `before` (count `(` and `)`, confirm depth returns to zero at the outermost `)`) so conditions like `if (fn(a, b)) {` are correctly classified as control-flow.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ Linked #2030
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ❌ 5/25 Preflight is holding this PR: the review lane is unavailable, so it is not ready for automated review.
Contributor workload ✅ 10/10 Author activity: 318 registered-repo PR(s), 186 merged, 9 issue(s).
Contributor context ✅ Confirmed Gittensor contributor bohdansolovie; Gittensor profile; 318 PR(s), 9 issue(s).
Gate result ✅ Passing No configured blocker found.
Review context
  • Author: bohdansolovie
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: Python, C++, JavaScript
  • Official Gittensor activity: 318 PR(s), 9 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Await review-lane availability.
  • Refresh registry data or choose a registered active repo.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

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


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@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.09%. Comparing base (eb8cb4f) to head (753361f).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3536   +/-   ##
=======================================
  Coverage   93.09%   93.09%           
=======================================
  Files         301      301           
  Lines       31450    31450           
  Branches    11483    11483           
=======================================
  Hits        29279    29279           
  Misses       1517     1517           
  Partials      654      654           
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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Gittensory approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 4332516 into JSONbored:main Jul 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(enrichment): deep-nesting / arrow-anti-pattern heuristic analyzer

1 participant