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 String typeName = node.constructorName.type.name.lexeme;
// Check for AndroidNotificationDetails constructor
if (typeName != 'AndroidNotificationDetails') return;
// Check if channelDescription is provided as named argument
bool hasChannelDescription = false;
bool hasImportance = false;
for (final Expression arg in node.argumentList.arguments) {
if (arg is NamedExpression) {
final String name = arg.name.label.name;
if (name == 'channelDescription') {
hasChannelDescription = true;
}
if (name == 'importance') {
hasImportance = true;
}
}
}
// Warn if missing channelDescription
if (!hasChannelDescription) {
reporter.atNode(node.constructorName, code);
return;
}
// Also suggest setting importance for visibility
if (!hasImportance) {
reporter.atNode(node.constructorName, code);
}
});
}