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.element?.name;
if (typeName == null || !_animatedWidgets.contains(typeName)) return;
// Check if wrapped in RepaintBoundary
AstNode? current = node.parent;
int depth = 0;
bool hasRepaintBoundary = false;
while (current != null && depth < 5) {
if (current is InstanceCreationExpression) {
final String? parentType = current.constructorName.type.element?.name;
if (parentType == 'RepaintBoundary') {
hasRepaintBoundary = true;
break;
}
}
current = current.parent;
depth++;
}
// Only report if inside Stack or complex layout (where isolation matters)
if (!hasRepaintBoundary) {
AstNode? parent = node.parent;
while (parent != null) {
if (parent is InstanceCreationExpression) {
final String? parentType =
parent.constructorName.type.element?.name;
if (parentType == 'Stack' ||
parentType == 'CustomMultiChildLayout') {
reporter.atNode(node.constructorName, code);
return;
}
}
parent = parent.parent;
}
}
});
}