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((node) {
    // Only check static methods
    if (!node.isStatic) return;
    final body = node.body;
    // Skip async methods - handled by more specific rules
    if (body is BlockFunctionBody) {
      if (body.isAsynchronous) return;
    }

    // Check parameters for BuildContext
    for (final param in node.parameters?.parameters ?? <FormalParameter>[]) {
      if (isBuildContextParam(param)) {
        reporter.atNode(param);
      }
    }
  });
}