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.addMethodInvocation((MethodInvocation node) {
if (!_geocodingMethods.contains(node.methodName.name)) return;
// Check if there's a cache lookup nearby in the enclosing function
AstNode? current = node.parent;
while (current != null) {
if (current is FunctionBody) {
final String bodySource = current.toSource();
// Look for cache patterns
if (RegExp(r'\bcache\b').hasMatch(bodySource) ||
RegExp(r'\bCache\b').hasMatch(bodySource) ||
RegExp(r'_geocode').hasMatch(bodySource) ||
RegExp(r'_placemark').hasMatch(bodySource) ||
RegExp(r'\bcached\b').hasMatch(bodySource)) {
return; // Has cache, OK
}
break;
}
current = current.parent;
}
reporter.atNode(node);
});
}