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) {
    final String typeName = node.constructorName.type.name.lexeme;
    if (!_providerTypes.contains(typeName)) return;

    // Skip if this is .value constructor
    if (node.constructorName.name?.name == 'value') return;

    // Check if child is also a Provider
    for (final Expression arg in node.argumentList.arguments) {
      if (arg is NamedExpression && arg.name.label.name == 'child') {
        final Expression childExpr = arg.expression;
        if (childExpr is InstanceCreationExpression) {
          final String childType = childExpr.constructorName.type.name.lexeme;
          if (_providerTypes.contains(childType)) {
            reporter.atNode(node);
            return;
          }
        }
      }
    }
  });
}