[tool] Add test_data directory to cognitive complexity check - #12523
[tool] Add test_data directory to cognitive complexity check#12523camsim99 wants to merge 3 commits into
test_data directory to cognitive complexity check#12523Conversation
There was a problem hiding this comment.
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.
| final filesToAnalyze = <String>[]; | ||
| for (final FileSystemEntity entity in package.libDirectory.listSync(recursive: true)) { | ||
| for (final FileSystemEntity entity in package.directory.listSync(recursive: true)) { | ||
| if (entity is File && entity.path.endsWith('.dart') && !_isGeneratedDartFile(entity.path)) { | ||
| final String relativePath = path.relative(entity.path, from: package.directory.path); | ||
| filesToAnalyze.add(relativePath.replaceAll(r'\', '/')); | ||
| final String posixPath = relativePath.replaceAll(r'\', '/'); | ||
| final bool isLib = posixPath.startsWith('lib/'); | ||
| final bool isRootEvalData = posixPath.startsWith('evals/test_data/'); | ||
| final bool isSkillEvalData = | ||
| posixPath.startsWith('.agents/skills/') && posixPath.contains('/evals/test_data/'); | ||
| if (isLib || isRootEvalData || isSkillEvalData) { | ||
| filesToAnalyze.add(posixPath); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Listing the entire package directory recursively (package.directory.listSync(recursive: true)) is highly inefficient and can cause significant performance bottlenecks in CI/CD pipelines, especially for large packages with many build artifacts (e.g., .dart_tool/, build/, ios/Pods/, node_modules/).
Since we only care about Dart files in lib/, evals/test_data/, and .agents/skills/, we should only recursively list those specific directories if they exist.
final List<Directory> directoriesToSearch = <Directory>[
package.libDirectory,
package.directory.childDirectory('evals').childDirectory('test_data'),
package.directory.childDirectory('.agents').childDirectory('skills'),
];
final List<String> filesToAnalyze = <String>[];
for (final Directory dir in directoriesToSearch) {
if (!dir.existsSync()) {
continue;
}
for (final FileSystemEntity entity in dir.listSync(recursive: true)) {
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'\', '/');
final bool isLib = posixPath.startsWith('lib/');
final bool isRootEvalData = posixPath.startsWith('evals/test_data/');
final bool isSkillEvalData =
posixPath.startsWith('.agents/skills/') && posixPath.contains('/evals/test_data/');
if (isLib || isRootEvalData || isSkillEvalData) {
filesToAnalyze.add(posixPath);
}
}
}
}
camera_android_cameraxusestest_datadirectories 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
[shared_preferences]///).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-assistbot 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
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