Sitelet https://github.com/flutter/packages/pull/12523
Skip to content

[tool] Add test_data directory to cognitive complexity check - #12523

Open
camsim99 wants to merge 6 commits into
flutter:mainfrom
camsim99:cogcomp_test_data
Open

camsim99 wants to merge 6 commits into
flutter:mainfrom
camsim99:cogcomp_test_data

Conversation

@camsim99

@camsim99 camsim99 commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

camera_android_camerax uses test_data directories for scripts used in evals for skills. Let's include those scripts in the cognitive complexity check. Follow up from #12369 (comment)

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 20, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request expands the cognitive_complexity analysis to include Dart files within evals/test_data and specific .agents/skills/ subdirectories, rather than limiting it to the lib/ directory. Feedback suggests optimizing performance by only recursively scanning the specific target directories instead of listing the entire package directory, which can contain large build artifacts.

Comment thread script/tool/lib/src/analyze_command.dart
@camsim99
camsim99 requested a review from reidbaker August 24, 2026 16:55
Comment thread script/tool/lib/src/analyze_command.dart Outdated
if (entity is File && entity.path.endsWith('.dart') && !_isGeneratedDartFile(entity.path)) {
final String relativePath = path.relative(entity.path, from: package.directory.path);
final String posixPath = relativePath.replaceAll(r'\', '/');
if (dir != skillsDir || posixPath.contains('/evals/test_data/')) {

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.

The code before made sense because it made sure we only handled dart files and ensured that it worked cross platform. I am not following why this change need to know about evals/test_data shouldnt that filter happen in the loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Refactored this so we now locate any evals/test_data directories under .agents/skills up front and append them to directoriesToSearch. The file collection loop now uses the original uniform logic without this filtering

final String relativePath = path.relative(entity.path, from: package.directory.path);
filesToAnalyze.add(relativePath.replaceAll(r'\', '/'));
for (final dir in directoriesToSearch) {
if (!dir.existsSync()) {

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.

Shouldnt the directory we configure in this tool always exist?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I now explicitly check if the lib directory, the evals/ directory, and the .agents/skills directory exists so it's clearer.

I think in practice we know camera_android_camerax is good to go, but if folks expand this check to an arbitrary plugin, I think it would be nice to catch the edge cases.

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 is there dart code we do not want to run cognitive_complexity on in a package? If not why not keep the existing dart file filtering and otherwise remove any directory configuration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, test files and example apps would fail the threshold because they're large test suites. Before this change, we only analyzed lib/, excluding tests, examples, generated code, and eval test data. This PR maintains those same exclusions but adss eval test data, which requires looking outside libDirectory. Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants