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) {
// Check for Firestore get or collection operations
final String methodName = node.methodName.name;
if (methodName != 'get' &&
methodName != 'collection' &&
methodName != 'doc') {
return;
}
// Check if it's Firestore-related (word-boundary to avoid FP)
final String source = node.toSource();
if (!RegExp(r'\bFirestore\b').hasMatch(source) &&
!RegExp(r'\bfirestore\b').hasMatch(source)) {
return;
}
// Check if inside build method
if (!_isInsideBuildMethod(node)) return;
// Allow if inside StreamBuilder or FutureBuilder
if (_isInsideBuilder(node)) return;
reporter.atNode(node);
});
}