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.addConstructorDeclaration((ConstructorDeclaration node) {
    for (final ConstructorInitializer initializer in node.initializers) {
      if (initializer is SuperConstructorInvocation) {
        // Check if super() has no arguments and no name
        if (initializer.constructorName == null &&
            initializer.argumentList.arguments.isEmpty) {
          reporter.atNode(initializer);
        }
      }
    }
  });
}