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.addMethodInvocation((MethodInvocation node) {
    final String methodName = node.methodName.name;
    if (methodName != 'print' && methodName != 'debugPrint') {
      return;
    }

    final NodeList<Expression> args = node.argumentList.arguments;
    if (args.isEmpty) return;

    final Expression firstArg = args.first;

    // Check if argument is a simple identifier (potential tear-off)
    if (firstArg is SimpleIdentifier) {
      // Check if it looks like a function name (starts with verb)
      final String name = firstArg.name;
      if (_looksLikeFunctionName(name)) {
        reporter.atNode(firstArg);
      }
    }
  });
}