cognitive_complexity
2.0.1, released 6 weeks ago by kevmoo.com
Algorithmic Cognitive Complexity calculation and Data-Flow analysis library and CLI tools.
What it does
Calculates algorithmic Cognitive Complexity and analyzes statement data-flow, file decomposition, and shallow helpers for Dart and Flutter. Includes CLI tools, a GitHub Action, and an AI agent skill for automated code quality gates.
AI-written summary of version 2.0.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to enforce a maximum cognitive complexity threshold in your CI pipeline.
- You need automated recommendations for splitting large files or safely extracting helper methods.
Skip it when
- You are looking for traditional style-only linters that do not evaluate complexity or data-flow.
- Your project uses a Dart SDK version older than 3.12.0.
Strengths
- Deterministic complexity engine without external LLM calls or token latency.
- Includes data-flow analysis, acyclic file decomposition, and git diff analysis.
- Provides ready-to-use GitHub Action integration.
Weaknesses
- Requires a minimum Dart SDK version of 3.12.0.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 7
Add the package to pubspec.yaml or run directly via `dart run cognitive_complexity`.
import 'package:cognitive_complexity/cognitive_complexity.dart';
void main() {
final analyzer = ComplexityAnalyzer();
final results = analyzer.analyzePath('lib');
for (final res in results) {
print('${res.name}: score is ${res.score} (${res.filePath}:L${res.startLine})');
}
}Alternatives
Packages that do the same job and could replace cognitive_complexity.
- lints
Provides official static analysis lint rules for Dart projects.
86Compare - flutter_lints
Provides recommended static analysis lints specifically for Flutter apps.
83Compare
Works with
Packages commonly used together with cognitive_complexity: ones it builds on, ones built on it, and its own family.
- analyzercognitive_complexity depends on itPerforms static analysis of Dart code for tool integration and embedding.
- stack_tracecognitive_complexity depends on itProvides parsing, inspection, and readable formatting of Dart stack traces.
- poolcognitive_complexity depends on itManage a finite pool of resources to control concurrent operations.
- iocognitive_complexity depends on itUtilities for the Dart VM Runtime including ANSI colors, file copying, and exit code values.
- argscognitive_complexity depends on itLibrary for parsing raw command-line arguments into options and values using GNU and POSIX styles.