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.addClassDeclaration((ClassDeclaration node) {
// Check if this is a State class
final ExtendsClause? extendsClause = node.extendsClause;
if (extendsClause == null) return;
final String superName = extendsClause.superclass.toSource();
if (!superName.startsWith('State<')) return;
// Check fields for large collection types
for (final ClassMember member in node.body.members) {
if (member is FieldDeclaration) {
final TypeAnnotation? type = member.fields.type;
if (type == null) continue;
final String typeSource = type.toSource();
for (final String pattern in _largeTypePatterns) {
if (typeSource.contains(pattern)) {
// Check if it's unbounded (no clear size limit)
final String fieldSource = member.toSource();
if (!fieldSource.contains('// bounded') &&
!fieldSource.contains('maxSize') &&
!fieldSource.contains('limit')) {
reporter.atNode(member);
break;
}
}
}
}
}
});
}