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 (!_isSvgPictureNode(node)) return;

    // Suppress when explicitly excluded from semantics (decorative SVG).
    final excludeArg = _namedArg(node, 'excludeFromSemantics');
    if (excludeArg != null) {
      final val = excludeArg.expression;
      // BooleanLiteral true → legitimately decorative, skip.
      if (val is BooleanLiteral && val.value) return;
    }

    // Suppress when a semanticsLabel is present and is not an empty literal.
    final labelArg = _namedArg(node, 'semanticsLabel');
    if (labelArg != null) {
      final val = labelArg.expression;
      // Any non-literal expression (variable, method call) is trusted.
      if (val is! StringLiteral) return;
      final strVal = val.stringValue;
      // Non-empty string literal → OK.
      if (strVal != null && strVal.isNotEmpty) return;
      // Empty string literal '' falls through and is reported.
    }

    reporter.atNode(node);
  });
}