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.addMethodDeclaration((MethodDeclaration node) {
    // Only check initState methods
    if (node.name.lexeme != 'initState') return;

    // Visit the body for bulk fetch calls
    final FunctionBody body = node.body;
    if (body is! BlockFunctionBody) return;

    _checkForBulkFetch(body.block, reporter);
  });
}