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.addConditionalExpression((ConditionalExpression node) {
// Check for nested ternary operators
if (node.thenExpression is ConditionalExpression ||
node.elseExpression is ConditionalExpression) {
reporter.atNode(node);
}
});
context.addCascadeExpression((CascadeExpression node) {
// Check for nested cascades
for (final Expression section in node.cascadeSections) {
if (section is CascadeExpression) {
reporter.atNode(section);
}
}
});
context.addBinaryExpression((BinaryExpression node) {
// Check for nested null-aware operators
if (node.operator.lexeme == '??') {
if (node.rightOperand case BinaryExpression right) {
if (right.operator.lexeme == '??') {
reporter.atNode(node);
}
}
}
});
}