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,
) {
// Check field declarations
context.addFieldDeclaration((FieldDeclaration node) {
final VariableDeclarationList fields = node.fields;
final TypeAnnotation? type = fields.type;
if (!_isVoidCallback(type)) return;
for (final VariableDeclaration variable in fields.variables) {
final String name = variable.name.lexeme;
if (type != null && _isAsyncSuggestingName(name)) {
reporter.atNode(type, code);
break; // Only report once per declaration
}
}
});
// Check parameter declarations (in constructors and functions)
context.addSimpleFormalParameter((SimpleFormalParameter node) {
final TypeAnnotation? type = node.type;
if (!_isVoidCallback(type)) return;
final Token? nameToken = node.name;
if (nameToken == null) return;
final String name = nameToken.lexeme;
if (type != null && _isAsyncSuggestingName(name)) {
reporter.atNode(type, code);
}
});
}