runWithReporter method

  1. @override
void runWithReporter(
  1. SaropaDiagnosticReporter reporter,
  2. SaropaContext context
)
override

Override this method to implement your lint rule.

Use context to register callbacks for AST node types:

context.addMethodInvocation((node) {
  if (condition) {
    reporter.atNode(node);
  }
});

Implementation

@override
void runWithReporter(
  SaropaDiagnosticReporter reporter,
  SaropaContext context,
) {
  context.addVariableDeclaration((node) {
    final name = node.name.lexeme;
    if (name.length >= 3) return;

    // Skip private and allowed short names
    if (name.startsWith('_')) return;
    if (_allowedShortNames.contains(name.toLowerCase())) return;

    // Skip C-style for-loop index variables
    if (node.parent?.parent is ForPartsWithDeclarations) return;

    // Skip variables in small blocks where context is immediately visible
    if (_isInSmallBlock(node)) return;

    reporter.atNode(node);
  });
}