Skip to content
pubscout

cognitive_complexity

2.0.1, released 6 weeks ago by kevmoo.com

Algorithmic Cognitive Complexity calculation and Data-Flow analysis library and CLI tools.

$ flutter pub add cognitive_complexity
Source repository

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.

  • flutter_lints

    Provides recommended static analysis lints specifically for Flutter apps.

Works with

Packages commonly used together with cognitive_complexity: ones it builds on, ones built on it, and its own family.