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((node) {
final name = node.constructorName.type.element?.name;
if (name == 'UnmodifiableListView' ||
name == 'UnmodifiableSetView' ||
name == 'UnmodifiableMapView') {
reporter.atNode(node);
}
});
context.addMethodInvocation((node) {
if (node.methodName.name == 'unmodifiable') {
final target = node.target;
if (target is SimpleIdentifier) {
final name = target.name;
if (name == 'List' || name == 'Set' || name == 'Map') {
reporter.atNode(node);
}
}
}
});
}