Summary
Add cognitive complexity measurement to Gaze by porting the Sonar cognitive complexity algorithm to Go AST analysis, and introduce a GazeCRAP-CC variant that incorporates cognitive complexity.
RFC: https://github.com/orgs/unbound-force/discussions/483 — Group 6
Phase: 3 (Depth)
Context
Cyclomatic complexity (used in CRAP scores) measures the number of linearly independent paths. Cognitive complexity (Sonar's algorithm) measures how hard code is to understand — penalizing nesting, recursion, and breaks in linear flow. Both are valuable; cognitive complexity better captures the human/agent comprehension burden.
Implementation
Cognitive Complexity Algorithm (Sonar Specification)
Port the SonarSource cognitive complexity specification to Go AST:
- Increments:
if, else if, else, switch, for, &&, ||, goto, sequences of logical operators, recursion
- Nesting penalty: +1 for each level of nesting on incremented structures
- No increment:
case labels, single ternary-like patterns
GazeCRAP-CC Variant
- Combine cognitive complexity with test coverage to produce an alternative CRAP-like score
- Formula:
GazeCRAP-CC = CC^2 * (1 - coverage)^3 + CC (mirrors CRAP but uses cognitive complexity)
- Reported alongside existing CRAP score, not replacing it
CI Gate Flag
gaze analyze ./... --max-cognitive-complexity=15
Acceptance Criteria
Dependencies
- Supports: Agent-design convention pack AD-001 (Group 3)
- Related: CRAP delta reporting (Group 2c)
- Repo:
gaze
Summary
Add cognitive complexity measurement to Gaze by porting the Sonar cognitive complexity algorithm to Go AST analysis, and introduce a
GazeCRAP-CCvariant that incorporates cognitive complexity.RFC: https://github.com/orgs/unbound-force/discussions/483 — Group 6
Phase: 3 (Depth)
Context
Cyclomatic complexity (used in CRAP scores) measures the number of linearly independent paths. Cognitive complexity (Sonar's algorithm) measures how hard code is to understand — penalizing nesting, recursion, and breaks in linear flow. Both are valuable; cognitive complexity better captures the human/agent comprehension burden.
Implementation
Cognitive Complexity Algorithm (Sonar Specification)
Port the SonarSource cognitive complexity specification to Go AST:
if,else if,else,switch,for,&&,||,goto, sequences of logical operators, recursioncaselabels, single ternary-like patternsGazeCRAP-CCVariantGazeCRAP-CC = CC^2 * (1 - coverage)^3 + CC(mirrors CRAP but uses cognitive complexity)CI Gate Flag
Acceptance Criteria
GazeCRAP-CCvariant computed and reported alongside CRAP--max-cognitive-complexity=15CI gate flagcognitive_complexityandgaze_crap_ccper functionDependencies
gaze