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,
) {
bool hasTokenRefreshHandler = false;
MethodInvocation? getTokenCall;
context.addPropertyAccess((PropertyAccess node) {
if (node.propertyName.name == 'onTokenRefresh') {
hasTokenRefreshHandler = true;
}
});
context.addMethodInvocation((MethodInvocation node) {
if (node.methodName.name == 'getToken') {
final Expression? target = node.target;
if (target == null) return;
final String targetSource = target.toSource();
if (RegExp(r'\bmessaging\b').hasMatch(targetSource) ||
RegExp(r'\bMessaging\b').hasMatch(targetSource) ||
RegExp(r'\bFirebaseMessaging\b').hasMatch(targetSource)) {
getTokenCall = node;
}
}
});
// Use addCompilationUnit to report at the end
context.addCompilationUnit((CompilationUnit unit) {
if (getTokenCall != null && !hasTokenRefreshHandler) {
reporter.atNode(getTokenCall!, code);
}
});
}