analyze method
Analyzes the given path and returns the resolved unit results.
If the path is a file, it will be analyzed as a single file. If the path is a directory, it will be analyzed as a directory.
Implementation
Future<List<AnalyzeFileResult>> analyze(List<String> paths) async {
final analyzed = <AnalyzeFileResult>[];
for (final p in paths) {
final path = switch (fs.path.isAbsolute(p)) {
true => p,
false => fs.path.canonicalize(
fs.path.join(fs.currentDirectory.path, p),
),
};
try {
if (fs.isDirectorySync(path)) {
final results = await _analyzeDirectory(path);
analyzed.addAll(results);
} else if (fs.isFileSync(path)) {
if (await _analyzeFile(path) case final result?) {
analyzed.add(result);
} else {
log.error('Could not analyze file: $path');
log.info(
'Make sure that your current directory is the root of your project',
);
continue;
}
} else {
log.error('Invalid path: $path');
continue;
}
} catch (e) {
log.debugError('Error analyzing path: $path');
log.debugError(' --- ');
log.debugError(e);
continue;
}
}
return analyzed;
}