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.addInstanceCreationExpression((InstanceCreationExpression node) {
final String typeName = node.constructorName.type.name.lexeme;
// Only check InkWell and MouseRegion
if (typeName != 'InkWell' && typeName != 'GestureDetector') return;
bool hasOnTap = false;
bool hasHoverHandling = false;
for (final Expression arg in node.argumentList.arguments) {
if (arg is NamedExpression) {
final String argName = arg.name.label.name;
if (argName == 'onTap' || argName == 'onPressed') {
hasOnTap = true;
}
if (argName == 'onHover' ||
argName == 'hoverColor' ||
argName == 'highlightColor') {
hasHoverHandling = true;
}
}
}
if (hasOnTap && !hasHoverHandling) {
reporter.atNode(node.constructorName, code);
}
});
}