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;
if (!_interactiveWidgets.contains(typeName)) return;
// Check for explicit small size constraints
double? width;
double? height;
for (final Expression arg in node.argumentList.arguments) {
if (arg is! NamedExpression) continue;
final String paramName = arg.name.label.name;
final Expression value = arg.expression;
if (paramName == 'width' && value is DoubleLiteral) {
width = value.value;
} else if (paramName == 'height' && value is DoubleLiteral) {
height = value.value;
} else if (paramName == 'width' && value is IntegerLiteral) {
width = value.value?.toDouble();
} else if (paramName == 'height' && value is IntegerLiteral) {
height = value.value?.toDouble();
} else if (paramName == 'iconSize' && value is DoubleLiteral) {
// IconButton uses iconSize
if (value.value < _minTouchSize) {
reporter.atNode(arg);
}
} else if (paramName == 'iconSize' && value is IntegerLiteral) {
if ((value.value ?? 0) < _minTouchSize) {
reporter.atNode(arg);
}
} else if (paramName == 'constraints') {
// Check BoxConstraints
_checkBoxConstraints(arg.expression, reporter);
}
}
// Report if explicit dimensions are too small
if (width != null && width < _minTouchSize) {
reporter.atNode(node);
} else if (height != null && height < _minTouchSize) {
reporter.atNode(node);
}
});
}