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 String methodName = node.methodName.name;
if (!_dbMethods.contains(methodName)) return;
final Expression? target = node.target;
if (target == null) return;
final String targetSource = target.toSource().toLowerCase();
if (!_dbTxnTargetPatterns.any((p) => p.hasMatch(targetSource))) {
return;
}
// Check if inside try-catch
AstNode? current = node.parent;
while (current != null) {
if (current is TryStatement) return;
if (current is FunctionBody) break;
current = current.parent;
}
reporter.atNode(node);
});
}