runCliAnalysis method
Future<Iterable<UnusedL10nFileReport> >
runCliAnalysis(
- Iterable<
String> folders, - String rootFolder,
- UnusedL10nConfig config, {
- String? sdkPath,
Returns a list of unused localization reports
for analyzing all files in the given folders
.
The analysis is configured with the config
.
Implementation
Future<Iterable<UnusedL10nFileReport>> runCliAnalysis(
Iterable<String> folders,
String rootFolder,
UnusedL10nConfig config, {
String? sdkPath,
}) async {
final collection =
createAnalysisContextCollection(folders, rootFolder, sdkPath);
final localizationUsages = <ClassElement, Set<String>>{};
for (final context in collection.contexts) {
final unusedLocalizationAnalysisConfig =
_getAnalysisConfig(context, rootFolder, config);
if (config.shouldPrintConfig) {
_logger?.printConfig(unusedLocalizationAnalysisConfig.toJson());
}
final filePaths = getFilePaths(
folders,
context,
rootFolder,
unusedLocalizationAnalysisConfig.globalExcludes,
);
final analyzedFiles =
filePaths.intersection(context.contextRoot.analyzedFiles().toSet());
for (final filePath in analyzedFiles) {
_logger?.infoVerbose('Analyzing $filePath');
final unit = await context.currentSession.getResolvedUnit(filePath);
_analyzeFile(unit, unusedLocalizationAnalysisConfig.classPattern)
.forEach((classElement, usages) {
localizationUsages.update(
classElement,
(value) => value..addAll(usages),
ifAbsent: () => usages,
);
});
}
}
return _checkUnusedL10n(localizationUsages, rootFolder);
}