Code Complexity
Tools and metrics for analyzing algorithmic complexity and cognitive burden in Dart and Flutter codebases.
cognitive_complexity
Algorithmic Cognitive Complexity calculation and Data-Flow analysis library and CLI tools for Dart and Flutter.
It implements the Cognitive Complexity principles articulated by SonarSource, providing an objective way to find and fix overly complex logic and routines.
Comparison: cyclomatic_complexity vs cognitive_complexity
Both tools aim to alert you when code becomes too complex to maintain, but they evaluate complexity from different angles:
cyclomatic_complexity | cognitive_complexity | |
|---|---|---|
| Complexity angle | Structural: Counts branches and execution paths | Perceptual: Evaluates mental effort and readability |
| Nesting impact | Treats all branches equally (+1 per branch) | Penalizes deeper nesting progressively |
| When it flags | Functions with too many execution paths | Functions that are hard for humans to follow |
| Tool type | Real-time IDE lint rule (solid_lints) | Standalone CLI tool & analysis library |
💡 Best Together: Use
cyclomatic_complexityinsolid_lintsto prevent sprawling branch counts, andcognitive_complexityto audit deeply nested routines that are hard to comprehend and maintain.