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 DartType? type = node.staticType;
if (type is! InterfaceType) return;
if (type.element.name != 'Container') return;
final String uri = type.element.library.uri.toString();
if (!uri.contains('flutter')) return;
final Set<String> namedArgNames = <String>{};
for (final Argument arg in node.argumentList.arguments) {
if (arg is NamedArgument) {
namedArgNames.add(arg.name.lexeme);
}
}
if (namedArgNames.any(_containerJustifyingArgNames.contains)) return;
reporter.atNode(node);
});
}