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 class extends Equatable or mixes in EquatableMixin
if (!isEquatable(node)) return;
// Check if class has copyWith method
bool hasCopyWith = false;
for (final ClassMember member in node.body.members) {
if (member is MethodDeclaration && member.name.lexeme == 'copyWith') {
hasCopyWith = true;
break;
}
}
if (!hasCopyWith) {
reporter.atNode(node);
}
});
}