Skip to content

[camera_android_camerax][tool] Migrate complexity checks to package:cognitive_complexity - #12356

Draft
reidbaker-agent wants to merge 3 commits into
flutter:mainfrom
reidbaker:migrate-cognitive-complexity-2026-08-03
Draft

[camera_android_camerax][tool] Migrate complexity checks to package:cognitive_complexity#12356
reidbaker-agent wants to merge 3 commits into
flutter:mainfrom
reidbaker:migrate-cognitive-complexity-2026-08-03

Conversation

@reidbaker-agent

@reidbaker-agent reidbaker-agent commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

When we initially added cyclomatic complexity we wanted cognitive complexity. Now there is a mit licensed version that meets our dependency constraints maintained by a flutter contributor so let's migrate to that.

PR is in draft pending updates to kevmoo/cognitive_complexity.dart#10 which lowers the analyzer bounds so this pr can get rid of the overrides.


Agent authored pr description

Migrates codebase complexity enforcement for camera_android_camerax from dart_code_linter (cyclomatic complexity) to package:cognitive_complexity (cognitive complexity), matching the migration in flutter/agent-plugins#211 and replacing #11999.

Summary

  • Replaced dart_code_linter with cognitive_complexity under pinned allowed dependencies in .repo_tool_config.yaml.
  • Updated AnalyzeCommand in script/tool/lib/src/analyze_command.dart to execute cognitive_complexity with configured fail thresholds from analysis_options.yaml while filtering out generated Dart files (.g.dart, .freezed.dart, .mocks.dart, .gen.dart).
  • Replaced dart_code_linter with cognitive_complexity: 0.2.0 in packages/camera/camera_android_camerax/pubspec.yaml and configured fail-threshold: 15 in analysis_options.yaml.
  • Added dependency_overrides for analyzer: ^14.1.0 and file: ^7.0.1 to resolve version constraints alongside pigeon.
  • Updated repository tooling unit tests in script/tool/test/analyze_command_test.dart to test cognitive_complexity and verify generated file exclusion.

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under.
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under.
  • All existing and new tests are passing.

…ognitive_complexity

Migrates codebase complexity enforcement for camera_android_camerax from dart_code_linter (cyclomatic complexity) to package:cognitive_complexity (cognitive complexity), matching the migration in flutter/agent-plugins#211 and replacing flutter#11999.

- Replaces dart_code_linter with cognitive_complexity under pinned allowed dependencies in .repo_tool_config.yaml.
- Updates AnalyzeCommand in script/tool/lib/src/analyze_command.dart to execute cognitive_complexity with configured fail thresholds from analysis_options.yaml while filtering out generated Dart files (.g.dart, .freezed.dart, .mocks.dart, .gen.dart).
- Replaces dart_code_linter with cognitive_complexity: 0.2.0 in packages/camera/camera_android_camerax/pubspec.yaml and configures fail-threshold: 15 in analysis_options.yaml.
- Adds dependency_overrides for analyzer: ^14.1.0 and file: ^7.0.1 to resolve version constraints alongside pigeon.
- Updates repository tooling unit tests in script/tool/test/analyze_command_test.dart to test cognitive_complexity and verify generated file exclusion.
@reidbaker reidbaker added the CICD Run CI/CD label Aug 4, 2026
Comment on lines +371 to +373
filePath.endsWith('.freezed.dart') ||
filePath.endsWith('.mocks.dart') ||
filePath.endsWith('.gen.dart');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all of these file types present in this codebase? if not then remove the matchers that do not match at least one expected file in this repo.

'cognitive_complexity',
if (threshold != null) ...<String>[
'--threshold',
(threshold > 5 ? threshold - 5 : 0).toString(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this threshold logic variable?

… document threshold logic

- Removes .freezed.dart from _isGeneratedDartFile in script/tool/lib/src/analyze_command.dart as .freezed.dart is not present in flutter/packages.
- Adds explanatory comment for setting --threshold to max(0, threshold - 5) when --fail-threshold is configured.
- Updates analyze_command_test.dart generated file test to use .mocks.dart and .gen.dart.
…ns are printed

Sets --threshold equal to threshold when --fail-threshold is configured so that cognitive_complexity only outputs declarations that violate the failure threshold.
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 4, 2026
@reidbaker reidbaker added the CICD Run CI/CD label Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants