Skip to main content

Code Complexity

Tools and metrics for analyzing algorithmic complexity and cognitive burden in Dart and Flutter codebases.

cognitive_complexity

pub package

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_complexitycognitive_complexity
Complexity angleStructural: Counts branches and execution pathsPerceptual: Evaluates mental effort and readability
Nesting impactTreats all branches equally (+1 per branch)Penalizes deeper nesting progressively
When it flagsFunctions with too many execution pathsFunctions that are hard for humans to follow
Tool typeReal-time IDE lint rule (solid_lints)Standalone CLI tool & analysis library

💡 Best Together: Use cyclomatic_complexity in solid_lints to prevent sprawling branch counts, and cognitive_complexity to audit deeply nested routines that are hard to comprehend and maintain.