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 (node.methodName.name != 'listen') return;
final Expression? target = node.target;
if (target == null) return;
final String targetSource = target.toSource();
if (!targetSource.endsWith('socket') &&
!targetSource.endsWith('Socket') &&
!targetSource.endsWith('channel') &&
!targetSource.endsWith('Channel')) {
return;
}
final ArgumentList args = node.argumentList;
if (args.arguments.isEmpty) return;
final Expression firstArg = args.arguments.first;
if (firstArg is! FunctionExpression) return;
final String bodySource = firstArg.body.toSource();
if (_validationBodyPatterns.any((p) => p.hasMatch(bodySource))) {
return;
}
reporter.atNode(node);
});
}