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,
) {
// File-level check: collect ALL method invocations across the compilation
// unit in a single pass, then decide once per file whether to report.
context.addCompilationUnit((CompilationUnit unit) {
// Import guard — only applies to files that import receive_sharing_intent.
// fileImportsPackage requires an AstNode; the beginToken's parent is the
// unit itself, so pass the unit directly.
if (!fileImportsPackage(unit, PackageImports.receiveSharingIntent)) {
return;
}
final _MethodNameCollector collector = _MethodNameCollector();
unit.accept(collector);
// No getMediaStream calls — nothing to report.
if (collector.getMediaStreamCalls.isEmpty) return;
// Both paths wired — compliant.
if (collector.getInitialMediaCalls.isNotEmpty) return;
// Report at the first getMediaStream call site so the diagnostic lands on
// the call that is "missing its partner" rather than on the file header.
reporter.atNode(collector.getMediaStreamCalls.first.methodName);
});
}