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.addSimpleStringLiteral((SimpleStringLiteral node) {
    final String value = node.value;

    // Skip if in test file
    final String filePath = context.filePath;
    if (filePath.contains('_test.dart') || filePath.contains('/test/')) {
      return;
    }

    // Check if value looks like a bundle ID
    if (_bundleIdPattern.hasMatch(value)) {
      // Check if it's being used in a bundle ID context
      AstNode? parent = node.parent;
      while (parent != null) {
        if (parent is VariableDeclaration) {
          final String varName = parent.name.lexeme.toLowerCase();
          if (varName.contains('bundle') ||
              varName.contains('package') ||
              varName.contains('appid')) {
            reporter.atNode(node);
            return;
          }
        }
        if (parent is NamedExpression) {
          final String paramName = parent.name.label.name.toLowerCase();
          if (paramName.contains('bundle') ||
              paramName.contains('package') ||
              paramName.contains('appid')) {
            reporter.atNode(node);
            return;
          }
        }
        parent = parent.parent;
      }
    }
  });
}