runWithReporter method
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.body.isAsynchronous) return;
// Check if in a State class
final classDecl = node.thisOrAncestorOfType<ClassDeclaration>();
if (classDecl == null) return;
final extendsClause = classDecl.extendsClause;
if (extendsClause == null) return;
final superclass = extendsClause.superclass;
if (superclass.name.lexeme != 'State') return;
if (superclass.typeArguments == null) return;
// Analyze the method body
node.body.visitChildren(_MountedCheckVisitor(reporter, code));
});
}