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 constructorSource = node.constructorName.toSource();
    if (!constructorSource.contains('CachedNetworkImage')) return;

    // Check if already has memCacheWidth or memCacheHeight
    for (final Expression arg in node.argumentList.arguments) {
      if (arg is NamedExpression) {
        final String name = arg.name.label.name;
        if (name == 'memCacheWidth' || name == 'memCacheHeight') {
          return; // Has cache bounds, OK
        }
      }
    }

    // Check if inside a list builder's itemBuilder
    if (_isInsideListBuilder(node)) {
      reporter.atNode(node.constructorName, code);
    }
  });
}