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 constructorSource = node.constructorName.toSource();
if (constructorSource != 'Image.network') return;
// Check for cacheWidth or cacheHeight parameter
bool hasCacheDimensions = false;
for (final Expression arg in node.argumentList.arguments) {
if (arg is NamedExpression) {
final String name = arg.name.label.name;
if (name == 'cacheWidth' || name == 'cacheHeight') {
hasCacheDimensions = true;
break;
}
}
}
if (!hasCacheDimensions) {
reporter.atNode(node.constructorName, code);
}
});
}