A cognitive complexity linter for Dart libraries or applications.
This plugin runs inside the Dart analysis server via
analysis_server_plugin,
with the complexity metric ported from
eslint-plugin-sonarjs.
Add the package as a dev dependency:
dev_dependencies:
dart_cognitive_complexity:Activate the plugin in your analysis_options.yaml:
analyzer:
plugins:
- dart_cognitive_complexityConfigure the threshold under a top-level cognitive_complexity: block in
analysis_options.yaml:
analyzer:
plugins:
- dart_cognitive_complexity
cognitive_complexity:
threshold: 15 # default 10To change the severity, use the analyzer's standard mechanism:
analyzer:
errors:
cognitive_complexity: warning # info | warning | errorThe diagnostics show up in any tool that talks to the analysis server
(dart analyze, your IDE, etc.) — no separate runner is needed.
Version 2.0 dropped custom_lint_builder. To migrate:
- Remove
custom_lintfrom your dev dependencies and fromanalyzer.plugins:. - Add
dart_cognitive_complexitydirectly underanalyzer.plugins:. - Move the rule options from the
custom_lint:block to a top-levelcognitive_complexity:block. - Replace any
severity:setting with the standardanalyzer.errors:block.