feat: multi-language complexity analysis#147
Conversation
Replace loose `!= null` checks with `typeof === 'number' && Number.isFinite()`
to prevent `Number("")`, `Number(null)`, and `Number(true)` from silently
coercing into valid SQL values. Add integration test verifying exceeds
arrays and summary.aboveWarn are correctly computed.
Addresses Greptile review feedback on #136.
Impact: 2 functions changed, 3 affected
Update README, CLAUDE.md, BACKLOG, titan-paradigm, recommended-practices, and CLI/MCP examples to reflect today's merged PRs: complexity metrics (#130/#139), Louvain community detection (#133/#134), and manifesto rule engine (#138). Updates MCP tool count from 21 to 24 (25 in multi-repo), marks backlog items 6/11/21/22 as done, and adds real CLI output examples.
When limit === undefined, limit !== 0 is always true — the && check was dead code. Simplified to just check limit === undefined. Impact: 2 functions changed, 18 affected
Test was named "handles non-numeric thresholds gracefully" but only validated baseline exceeds/aboveWarn with valid thresholds. Actual non-numeric threshold tests exist separately. Renamed to "produces correct exceeds and aboveWarn with valid thresholds".
Parameterize the complexity algorithm to support all 10 languages instead of just JS/TS/TSX. Add per-language COMPLEXITY_RULES, HALSTEAD_RULES, and COMMENT_PREFIXES with three else-if detection patterns (else-wraps-if, explicit elif, alternative field). Guard against tree-sitter keyword leaf tokens that share node type names with their parent constructs. Impact: 4 functions changed, 4 affected
|
Claude finished @carlos-alm's task —— View job Code Review Complete ✅Reviewing PR: feat: multi-language complexity analysis Review Checklist:
Root Cause AnalysisProblem Being Solved: Codegraph only supported complexity analysis for JavaScript/TypeScript/TSX. Users needed complexity metrics for Python, Go, Rust, Java, C#, Ruby, and PHP to get comprehensive code quality insights across their multilingual codebases. Why This Approach: The PR parameterizes the complexity algorithm with language-specific rules maps ( Risk Assessment: LOW RISK. This is additive functionality that doesn't change existing JS/TS behavior. All existing tests pass, comprehensive test coverage added. Critical Concerns✅ No Configuration Relaxations: No linting rules disabled, no test timeouts increased, no coverage thresholds lowered. ✅ Test Integrity Excellent: 61 new language-specific test cases added with comprehensive coverage:
✅ Implementation Quality:
✅ Incremental Logic: Native engine provides pre-computed complexity when available, WASM fallback only when needed. Efficient resource usage. Code Quality Observations: Strengths (
|
Greptile SummaryThis PR successfully extends complexity analysis from JS/TS/TSX to all 10 supported languages by parameterizing the complexity algorithm and adding language-specific rules. Key changes
Quality indicators
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
Start[computeFunctionComplexity] --> CheckBranch{Node in<br/>branchNodes?}
CheckBranch -->|No| CheckOther[Check other node types]
CheckBranch -->|Yes| CheckChildCount{childCount > 0?}
CheckChildCount -->|No| Skip[Skip - keyword leaf token]
CheckChildCount -->|Yes| CheckElseType{Is elseNodeType?}
CheckElseType -->|Yes - Pattern A| CheckElseChild{First child is<br/>ifNodeType?}
CheckElseChild -->|Yes| ElseIf[else-if: walk children<br/>+1 cognitive, +1 cyclomatic]
CheckElseChild -->|No| PlainElse[plain else: walk children<br/>+1 cognitive]
CheckElseType -->|No| CheckElif{Is elifNodeType?}
CheckElif -->|Yes - Pattern B| ElifNode[elif node: walk children<br/>+1 cognitive, +1 cyclomatic]
CheckElif -->|No| CheckIfNode{Is ifNodeType?}
CheckIfNode -->|Yes| CheckElseViaAlt{elseViaAlternative?}
CheckElseViaAlt -->|Yes - Pattern C| CheckAltField{Is alternative<br/>of parent if?}
CheckAltField -->|Yes| ElseIfAlt[else-if via alternative:<br/>+1 cognitive, +1 cyclomatic]
CheckAltField -->|No| NormalIf[normal if:<br/>+1+nesting cognitive]
CheckElseViaAlt -->|No| CheckParentElse{Parent is<br/>elseNodeType?}
CheckParentElse -->|Yes - Pattern A| ElseIfNested[else-if nested:<br/>+1 cognitive, +1 cyclomatic]
CheckParentElse -->|No| NormalIf
CheckIfNode -->|No| CheckPlainElseAlt{Pattern C<br/>plain else?}
CheckPlainElseAlt -->|Yes| PlainElseAlt[plain else via alternative:<br/>+1 cognitive]
CheckPlainElseAlt -->|No| OtherBranch[other branch node:<br/>+1+nesting cognitive]
subgraph "Pattern A: JS/C#/Rust"
PA[else_clause wraps if_statement]
end
subgraph "Pattern B: Python/Ruby/PHP"
PB[explicit elif/elsif/elseif node]
end
subgraph "Pattern C: Go/Java"
PC[alternative field on if_statement]
end
Last reviewed commit: b4f0c28 |
Summary
#for Python/Ruby, mixed for PHP)Test plan
node src/cli.js complexity -Tshows metrics for non-JS functions (Go, Python, Ruby, PHP, Java, Rust extractors all appear)npm run lint)