runCliAnalysis method

Future<Iterable<LintFileReport>> runCliAnalysis(
  1. Iterable<String> folders,
  2. String rootFolder,
  3. LintConfig config, {
  4. 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, analyzedFiles, report) = prepareLintAnalysis(
      context,
      folders,
      rootFolder,
      config,
      collection,
    );

    if (report != null) {
      analyzerResult.add(report);
    }

    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;
}