in lib/src/rules/lines_longer_than_80_chars.dart [177:226]
void visitCompilationUnit(CompilationUnit node) {
var lineInfo = node.lineInfo;
if (lineInfo == null) {
return;
}
var lineCount = lineInfo.lineCount;
var longLines = <_LineInfo>[];
for (var i = 0; i < lineCount; i++) {
var start = lineInfo.getOffsetOfLine(i);
int end;
if (i == lineCount - 1) {
end = node.end;
} else {
end = lineInfo.getOffsetOfLine(i + 1) - 1;
var length = end - start;
if (length > 80) {
if (context.currentUnit.content[end] == _lf &&
context.currentUnit.content[end - 1] == _cr) {
end--;
}
}
}
var length = end - start;
if (length > 80) {
// Use 80 as the start of the range so that navigating to the lint
// will place the caret at exactly the location where the line needs
// to wrap.
var line = _LineInfo(index: i, offset: start + 80, end: end);
longLines.add(line);
}
}
if (longLines.isEmpty) return;
var allowedLineVisitor = _AllowedLongLineVisitor(lineInfo);
node.accept(allowedLineVisitor);
var allowedCommentVisitor = _AllowedCommentVisitor(lineInfo);
node.accept(allowedCommentVisitor);
var allowedLines = [
...allowedLineVisitor.allowedLines,
...allowedCommentVisitor.allowedLines
];
for (var line in longLines) {
if (allowedLines.contains(line.index + 1)) continue;
rule.reporter
.reportErrorForOffset(rule.lintCode, line.offset, line.length);
}
}