run method

  1. @override
void run(
  1. CustomLintResolver resolver,
  2. ErrorReporter reporter,
  3. CustomLintContext context
)

Emits lints for a given file.

run will only be invoked with files respecting filesToAnalyze

Implementation

@override
void run(
  CustomLintResolver resolver,
  ErrorReporter reporter,
  CustomLintContext context,
) {
  context.registry.addInstanceCreationExpression((node) {
    final type = node.staticType;
    if (type == null) return;

    final isFirebaseMatch = firebaseMatchChecker.isAssignableFromType(type);
    final isDatabaseMatch = databaseMatchChecker.isAssignableFromType(type);

    if (!isFirebaseMatch && !isDatabaseMatch) return;

    final arguments = node.argumentList.arguments;
    final path = resolveMatchPath(arguments: arguments);
    if (path == null) return;

    for (final parameter in {
      'matches',
      'rules',
      'read',
      'write',
      'validate',
    }) {
      final node = arguments
          .whereType<NamedExpression>()
          .firstWhereOrNull((e) => e.name.label.name == parameter)
          ?.expression;
      if (node == null || node is! FunctionExpression) continue;

      final expectedSignature = validateSignature(
        path: path,
        wildcardMatcher: isFirebaseMatch ? r'{(\w+)}' : r'\$(\w+)',
        function: node,
        createExpectedSignature: (wildcard) => isFirebaseMatch
            ? '($wildcard, request, resource)'
            : '($wildcard)',
      );
      if (expectedSignature != null) {
        reporter.deprecatedReportErrorForNode(
          code,
          node.parameters!,
          null,
          null,
          expectedSignature,
        );
      }
    }
  });
}