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,
) {
// Inverse of the web-gate pattern: this rule warns that `dart:html`
// & friends crash at startup on mobile/desktop. A web-only project
// (no android/ios/macos/windows/linux directories at the project
// root) can't hit that failure mode, so every diagnostic is noise.
// Pure Dart libraries default true (consumers' targets unknown).
// See sibling bug report
// bugs/platform_gate_missing_from_sibling_rules.md.
if (!ProjectContext.hasNonWebPlatform(context.filePath)) return;
context.addImportDirective((ImportDirective node) {
final String? uri = node.uri.stringValue;
if (uri == null) return;
if (_webOnlyImports.contains(uri)) {
// Check if it's a conditional import
if (node.configurations.isNotEmpty) {
return; // Conditional import is fine
}
reporter.atNode(node);
}
});
}