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,
) {
// Check every method invocation; only test()/group() calls are relevant.
context.addMethodInvocation((MethodInvocation node) {
final String methodName = node.methodName.name;
// test(), testWidgets(), and group() all accept the solo named parameter.
if (methodName != 'test' &&
methodName != 'testWidgets' &&
methodName != 'group') {
return;
}
// Look for a named `solo: true` argument among the call's arguments.
for (final Expression arg in node.argumentList.arguments) {
if (arg is NamedExpression &&
arg.name.label.name == 'solo' &&
arg.expression is BooleanLiteral &&
(arg.expression as BooleanLiteral).value == true) {
// Flag the `solo: true` argument itself for a precise error location.
reporter.atNode(arg);
return;
}
}
});
}