runCliAnalysis method
Future<Iterable<LintFileReport> >
runCliAnalysis(
- Iterable<
String> folders, - String rootFolder,
- LintConfig config, {
- String? sdkPath,
Returns a list of lint reports for analyzing all files in the given folders
.
The analysis is configured with the config
.
Implementation
Future<Iterable<LintFileReport>> runCliAnalysis(
Iterable<String> folders,
String rootFolder,
LintConfig config, {
String? sdkPath,
}) async {
final collection =
createAnalysisContextCollection(folders, rootFolder, sdkPath);
final analyzerResult = <LintFileReport>[];
for (final context in collection.contexts) {
final lintAnalysisConfig =
_getAnalysisConfig(context, rootFolder, config);
final report = LintAnalysisOptionsValidator.validateOptions(
lintAnalysisConfig,
rootFolder,
);
if (report != null) {
analyzerResult.add(report);
}
if (config.shouldPrintConfig) {
_logger?.printConfig(lintAnalysisConfig.toJson());
}
final filePaths = getFilePaths(
folders,
context,
rootFolder,
lintAnalysisConfig.globalExcludes,
);
final analyzedFiles =
filePaths.intersection(context.contextRoot.analyzedFiles().toSet());
final contextsLength = collection.contexts.length;
final filesLength = analyzedFiles.length;
final updateMessage = contextsLength == 1
? 'Analyzing $filesLength file(s)'
: 'Analyzing ${collection.contexts.indexOf(context) + 1}/$contextsLength contexts with $filesLength file(s)';
_logger?.progress.update(updateMessage);
for (final filePath in analyzedFiles) {
_logger?.infoVerbose('Analyzing $filePath');
final unit = await context.currentSession.getResolvedUnit(filePath);
if (unit is ResolvedUnitResult) {
final result = _analyzeFile(
unit,
lintAnalysisConfig,
rootFolder,
filePath: filePath,
);
if (result != null) {
_logger?.infoVerbose(
'Analysis result: found ${result.issues.length} issues',
);
analyzerResult.add(result);
}
}
}
}
return analyzerResult;
}