Issue.fromAnalyzer constructor

Issue.fromAnalyzer(
  1. String analyzerLine
)

Dart Analysis Server Specification tells us that dartanalyzer produces machine output in format AnalysisErrorSeverity|AnalysisErrorType| code|path|line|column|length|description where:

  • AnalysisErrorSeverity is an enumeration of the possible severities of analysis errors (INFO, WARNING, or ERROR)
  • AnalysisErrorType is an enumeration of the possible types of analysis errors (CHECKED_MODE_COMPILE_TIME_ERROR, COMPILE_TIME_ERROR, HINT, LINT, STATIC_TYPE_WARNING, STATIC_WARNING, SYNTACTIC_ERROR, or TODO)
  • code is the name, as string, of the error code associated with this error.
  • path is the file containing the analysis error.
  • line is the one-based index of the line containing the first character of the range.
  • column is the offset of the range.
  • length is the length of the range.
  • description is the message to be displayed for this error. The message should indicate what is wrong with the code and why it is wrong.

Dart Analysis Server API Specification: https://htmlpreview.github.io/?https://github.com/dart-lang/sdk/blob/master/pkg/analysis_server/doc/api.html

Implementation

factory Issue.fromAnalyzer(String analyzerLine) {
  List<String> segments = analyzerLine.split('|');

  int line = int.parse(segments[4]);
  int beginColumn = int.parse(segments[5]);
  int endColumn = beginColumn + int.parse(segments[6]);

  return Issue(
    severity: parseSeverity(segments[0]),
    checkName: segments[2],
    location: {
      'path': relativizePath(segments[3]),
      'positions': {
        'begin': {
          'line': line,
          'column': beginColumn,
        },
        'end': {
          'line': line,
          'column': endColumn,
        },
      },
    },
    description: segments[7],
    fingerprint: md5(analyzerLine),
  );
}