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) {
    if (node.constructorName.type.name.lexeme != 'RetrieveEventsParams') {
      return;
    }
    if (!fileImportsPackage(node, PackageImports.deviceCalendar)) return;

    final bool hasStart = _argProvided(node, 'startDate');
    final bool hasEnd = _argProvided(node, 'endDate');
    final bool hasIds = _argProvided(node, 'eventIds');

    // Exactly one bound, and not rescued by an eventIds path.
    if (hasStart == hasEnd) return;
    if (hasIds) return;

    reporter.atNode(node);
  });
}