runWithReporter method

  1. @override
void runWithReporter(
  1. SaropaDiagnosticReporter reporter,
  2. SaropaContext context
)
override

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) {
    // Import gate: only flag files that import webview_flutter, preventing
    // false positives from unrelated WebView classes in non-webview projects.
    if (!fileImportsPackage(node, PackageImports.webviewFlutter)) return;

    // Match the constructor's named type exactly. 'WebView' is the removed
    // widget; 'WebViewWidget' is the v4 replacement and must NOT be flagged.
    // Syntactic name matching (not resolved element) keeps this rule working
    // under the scan CLI, which does not always resolve elements.
    final String typeName = node.constructorName.type.name.lexeme;
    if (typeName != 'WebView') return;

    reporter.atNode(node);
  });
}