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) {
    if (node.name.lexeme != 'build') return;

    // Only Flutter widget/State builds; skips non-widget `build` methods
    // such as Serverpod's WidgetRoute.build(Session, Request).
    final classDecl = node.parent?.parent;
    if (classDecl is! ClassDeclaration || !isWidgetOrStateClass(classDecl)) {
      return;
    }

    if (node.body.isAsynchronous) {
      reporter.atToken(node.name, code);
    }
  });
}