findDartFiles method
Find all Dart files under projectPath, excluding generated files and
build directories.
Results are returned as absolute, normalized paths. The scan stops after
_maxFiles files to avoid blowing up memory on monorepos.
Implementation
Future<List<String>> findDartFiles(String projectPath) async {
final normalizedRoot = p.normalize(p.absolute(projectPath));
final dir = Directory(normalizedRoot);
if (!dir.existsSync()) {
Logger.warn('Project path does not exist: $normalizedRoot');
return const [];
}
final files = <String>[];
await for (final entity in dir.list(recursive: true, followLinks: false)) {
if (entity is! File) continue;
if (!entity.path.endsWith('.dart')) continue;
final relative = p.relative(entity.path, from: normalizedRoot);
// Skip generated files.
if (_isGenerated(relative)) continue;
// Skip excluded directories.
if (_isInExcludedDir(relative)) continue;
files.add(p.normalize(entity.path));
if (files.length >= _maxFiles) {
Logger.warn(
'Reached max files limit ($_maxFiles). '
'Set MAX_FILES_TO_ANALYZE to increase.',
);
break;
}
}
Logger.debug('Found ${files.length} Dart files in $normalizedRoot');
return files;
}