parseStyleGuideViolation method
- @visibleForTesting
Parse a lint result line.
violation
to be parsed.
projectDir
containing this file.
Implementation
@visibleForTesting
CodeStyleViolation parseStyleGuideViolation(
final String violation, [
String? projectDir,
]) {
if (violation.isEmpty) {
throw const UnrecoverableException(
'violation check is empty',
exitParsingViolationFailed,
);
}
final Iterable<RegExpMatch> matches = _regexp.allMatches(violation);
if (matches.isEmpty) {
if (violation.endsWith('is a part and cannot be analyzed.')) {
String filePath = violation.split(' ').first;
if (projectDir != null) {
filePath = getFileRelativePath(filePath, projectDir);
}
return CodeStyleViolation.invalid(filePath);
}
throw UnrecoverableException(
'Does not match any of the expected value: $violation ',
exitParsingViolationFailed,
);
} else {
final RegExpMatch result = matches.single;
// starting from one because it's the
final ViolationSeverity severity = ViolationSeverity.withId(result[1]!);
final String type = result[2]!;
final String rule = result[3]!;
String filePath = result[4]!;
if (projectDir != null) {
filePath = getFileRelativePath(filePath, projectDir);
}
final int lineNumber = int.parse(result[5]!);
final int lineColumn = int.parse(result[6]!);
final String lintRuleDescription = result[8]!;
return CodeStyleViolation(
severity: severity,
type: type,
file: filePath,
line: lineNumber,
lineColumn: lineColumn,
rule: rule,
ruleDescription: lintRuleDescription,
);
}
}