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) {
final methodName = node.methodName.name;
// Check for Get.put() and Get.find()
if (methodName != 'put' && methodName != 'find') return;
final target = node.target;
if (target is! SimpleIdentifier) return;
if (target.name != 'Get') return;
// Check if this is at top level (main) or in a field initializer
AstNode? current = node.parent;
while (current != null) {
if (current is FunctionDeclaration && current.name.lexeme == 'main') {
reporter.atNode(node);
return;
}
if (current is FieldDeclaration) {
reporter.atNode(node);
return;
}
current = current.parent;
}
});
}