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) {
// Skip build method
if (node.name.lexeme == 'build') return;
if (_isNullableWidgetReturn(node.returnType)) {
reporter.atToken(node.name, code);
}
});
// Also check function declarations (top-level functions)
context.addFunctionDeclaration((FunctionDeclaration node) {
if (_isNullableWidgetReturn(node.returnType)) {
reporter.atToken(node.name, code);
}
});
}