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,
) {
  // The rule's value is in rendering an appropriate cursor on
  // platforms that show one by default: web + desktop
  // (macos/windows/linux). Pure-mobile Flutter apps (android/ios
  // only, no web/desktop) don't render a cursor, so the rule's
  // diagnostics are UX-irrelevant noise. See sibling bug report
  // bugs/platform_gate_missing_from_sibling_rules.md.
  if (!ProjectContext.hasPointerPlatform(context.filePath)) return;

  context.addInstanceCreationExpression((InstanceCreationExpression node) {
    final String typeName = node.constructorName.type.name.lexeme;
    if (!_interactiveWidgets.contains(typeName)) return;

    bool hasOnTap = false;
    bool hasMouseCursor = false;

    for (final Expression arg in node.argumentList.arguments) {
      if (arg is NamedExpression) {
        final String argName = arg.name.label.name;
        if (argName == 'onTap' || argName == 'onPressed') {
          hasOnTap = true;
        }
        if (argName == 'mouseCursor') {
          hasMouseCursor = true;
        }
      }
    }

    if (hasOnTap && !hasMouseCursor) {
      reporter.atNode(node.constructorName, code);
    }
  });
}