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,
) {
// Only check test files
final String path = context.filePath;
if (!path.contains('_test.dart') &&
!path.contains('/test/') &&
!path.contains(r'\test\')) {
return;
}
context.addMethodInvocation((MethodInvocation node) {
final String methodName = node.methodName.name;
if (methodName != 'test' && methodName != 'testWidgets') return;
final ArgumentList args = node.argumentList;
if (args.arguments.length < 2) return;
final Expression? bodyArg = args.arguments.length >= 2
? args.arguments[1]
: null;
if (bodyArg == null) return;
final String bodySource = bodyArg.toSource();
// Skip if using mocks (word-boundary to avoid FP)
if (_mockSkipPatterns.any((p) => p.hasMatch(bodySource))) return;
// Check for network patterns (word-boundary regex)
if (_networkPatternRegexps.any((p) => p.hasMatch(bodySource))) {
reporter.atNode(node.methodName, code);
}
});
}