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) {
final String methodName = node.methodName.name;
if (methodName != 'push' && methodName != 'pushNamed') return;
// Check if passing complex objects instead of IDs
for (final arg in node.argumentList.arguments) {
if (arg is NamedExpression && arg.name.label.name == 'arguments') {
// Check if passing an object that's not a simple type
final value = arg.expression;
if (value is! SimpleStringLiteral &&
value is! IntegerLiteral &&
value is! DoubleLiteral &&
value is! BooleanLiteral) {
// Inspect named-argument LABELS via the AST instead of substring-
// matching `id:` in the source. 'valueSource.contains("id:")'
// matched `uuid:` and `valid:`, suppressing the warning for objects
// that carry no real id. An exact `id` argument label (or a literal
// 'id' map key) means the object passes a routable identifier.
if (!_carriesIdArgument(value)) {
reporter.atNode(arg);
}
}
}
}
});
}