check method

  1. @override
List<Issue> check(
  1. ParsedFile file
)
override

Inspect a parsed file and return any findings.

MUST be pure (no side effects, no I/O). MUST be fast (<10ms typical). MUST return an empty list rather than throw on unexpected input.

Implementation

@override
List<Issue> check(ParsedFile file) {
  final issues = <Issue>[];
  Token? token = file.unit.beginToken;
  while (token != null) {
    var comment = token.precedingComments;
    while (comment != null) {
      final text = comment.lexeme;
      if (_todoPattern.hasMatch(text)) {
        final loc = file.unit.lineInfo.getLocation(comment.offset);
        issues.add(
          Issue(
            ruleId: 'todo_comment',
            category: 'quality',
            severity: Severity.info,
            message: text.trim(),
            filePath: file.source.path,
            line: loc.lineNumber,
            column: loc.columnNumber,
            codeSnippet: file.lineAt(loc.lineNumber),
            suggestion: 'Resolve the TODO or file an issue and reference it',
          ),
        );
      }
      comment = comment.next as dynamic;
    }
    if (token == token.next || token.next == null) break;
    token = token.next;
  }
  return issues;
}