convertAnalysisErrors method

List<AnalysisError> convertAnalysisErrors(
  1. List<AnalysisError> errors, {
  2. LineInfo? lineInfo,
  3. AnalysisOptions? options,
})

Converts the list of analysis errors from the 'analyzer' package to a list of analysis errors defined by the plugin API.

The severities of the errors are altered based on options.

Implementation

List<plugin.AnalysisError> convertAnalysisErrors(
  List<analyzer.AnalysisError> errors, {
  // TODO(srawlins): Make `lineInfo` required and non-nullable, in a breaking
  // change release.
  analyzer.LineInfo? lineInfo,
  // TODO(srawlins): Make `options` required and non-nullable, in a breaking
  // change release.
  analyzer.AnalysisOptions? options,
}) {
  var serverErrors = <plugin.AnalysisError>[];
  for (var error in errors) {
    var processor = analyzer.ErrorProcessor.getProcessor(options, error);
    if (processor != null) {
      var severity = processor.severity;
      // Errors with null severity are filtered out.
      if (severity != null) {
        // Specified severities override.
        serverErrors.add(convertAnalysisError(error,
            lineInfo: lineInfo, severity: severity));
      }
    } else {
      serverErrors.add(convertAnalysisError(error, lineInfo: lineInfo));
    }
  }
  return serverErrors;
}