feat(index): Sonar cognitive complexity column and recipes#173
Conversation
Add symbols.cognitive_complexity in the same oxc walk as cyclomatic, including class methods. Ship high-cognitive-complexity (min_score 15) and extend high-complexity-untested SELECT. Schema v38; plan deleted.
🦋 Changeset detectedLatest commit: 720aaa5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (19)
✅ Files skipped from review due to trivial changes (11)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThis PR integrates SonarSource cognitive-complexity measurement into the codebase and introduces a new development hardening workflow. The cognitive-complexity feature extends the existing cyclomatic-complexity analysis to detect nesting-heavy control flow, while the harden-pr skill automates PR validation before opening. ChangesCognitive Complexity Feature
Development Workflow Tooling
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Else-if alternates no longer inherit consequent cognitive nesting; golden pins labyrinth cognitive_complexity at 27 on minimal fixture.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/db.ts (1)
65-65: ⚡ Quick winAdd an index for the new
cognitive_complexityquery path.Line 65 introduces a new filter/sort column used by recipes; without an index, SQLite must scan/sort
symbolsfor each run.💡 Suggested patch
@@ CREATE INDEX IF NOT EXISTS idx_symbols_file ON symbols(file_path); + CREATE INDEX IF NOT EXISTS idx_symbols_cognitive ON symbols(cognitive_complexity, complexity, file_path, name) + WHERE cognitive_complexity IS NOT NULL;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/db.ts` at line 65, Add a SQLite index for the new cognitive_complexity column on the symbols table so queries that filter or sort by cognitive_complexity don't cause full table scans; update the DB migration or schema code that defines the symbols table (look for the CREATE TABLE or migration function that mentions cognitive_complexity and the symbols table) to create an index (e.g., CREATE INDEX IF NOT EXISTS idx_symbols_cognitive_complexity ON symbols(cognitive_complexity)) and ensure the migration runs in existing deployments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/extractors/types.ts`:
- Around line 77-78: The new public methods enterCognitiveNest() and
exitCognitiveNest() on ComplexityTracker are missing documentation; add concise
JSDoc comments immediately above each exported signature explaining their
purpose and nesting semantics (e.g., enterCognitiveNest begins a nested
cognitive complexity scope, increments the nest depth or stack, and
exitCognitiveNest closes that scope and decrements the depth, including behavior
when called without a matching enter), mention any side-effects (state mutated,
not reentrant) and expected usage example or pairing requirement (enter must be
paired with exit). Ensure the comments are placed with the exported API (the
ComplexityTracker methods) so they satisfy the public-API documentation
guideline.
---
Nitpick comments:
In `@src/db.ts`:
- Line 65: Add a SQLite index for the new cognitive_complexity column on the
symbols table so queries that filter or sort by cognitive_complexity don't cause
full table scans; update the DB migration or schema code that defines the
symbols table (look for the CREATE TABLE or migration function that mentions
cognitive_complexity and the symbols table) to create an index (e.g., CREATE
INDEX IF NOT EXISTS idx_symbols_cognitive_complexity ON
symbols(cognitive_complexity)) and ensure the migration runs in existing
deployments.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ffd31472-25e8-4597-b239-6743aeceaf43
📒 Files selected for processing (21)
.changeset/cognitive-complexity.mddocs/architecture.mddocs/glossary.mddocs/plans/ast-hash-duplication.mddocs/plans/cognitive-complexity.mddocs/plans/graph-estimated-crap.mddocs/roadmap.mdfixtures/golden/minimal/high-cognitive-complexity.jsonfixtures/golden/minimal/high-complexity-untested.jsonfixtures/golden/scenarios.jsonsrc/db.tssrc/extractors/complexity.test.tssrc/extractors/complexity.tssrc/extractors/symbols.tssrc/extractors/types.tssrc/parser.test.tstemplates/agent-content/rule/00-full.mdtemplates/recipes/high-cognitive-complexity.mdtemplates/recipes/high-cognitive-complexity.sqltemplates/recipes/high-complexity-untested.mdtemplates/recipes/high-complexity-untested.sql
💤 Files with no reviewable changes (2)
- docs/plans/cognitive-complexity.md
- docs/roadmap.md
Codifies the review-until-clean loop as a Tier-3 skill with lite (per tracer bullet) and full (pre-PR) modes, and wires lite harden into tracer-bullets cadence.
Minor changeset for SCHEMA 38 rebuild, agent rule column ref, arrow/bind test coverage, and doc/comment hygiene from harden-pr review.
README content_hash drifted when fixtures/minimal/README.md listed high-cognitive-complexity; golden now matches indexer line_count.
Skill invocation now authorizes the end commit and forbids asking about commits, babysit, or the next pass until the loop finishes.
insertSymbols SELECT test mirrors visibility pattern; v27 rebuild asserts symbols.cognitive_complexity via pragma_table_info.
Defines pristine/maximum production readiness as the north star reviewers optimize for, with an explicit checklist and production-bar status in reports.
…acker Mirror enterNest/exitNest one-liners; addresses CodeRabbit PR #173 thread.
Summary
symbols.cognitive_complexity(SonarSource rules) in the same oxc walk as cyclomatic McCabe —SCHEMA_VERSION38.markArrowSymbolonFunctionExpression).high-cognitive-complexity(min_scoredefault 15).high-complexity-untestedSELECT withcognitive_complexity(cyclomatic>= 10filter unchanged).Grill decisions (locked)
min_scoredefault 15 (Sonar-aligned)high-complexity-untestedTest plan
bun test src/extractors/complexity.test.ts src/parser.test.tsbun run test:goldenbun run typecheckbun src/index.ts query --recipe high-cognitive-complexity --jsonon minimal fixtureSummary by CodeRabbit
New Features
--params min_score.Documentation