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;

    final wildcards =
        RegExp(isFirebaseMatch ? r'{(\w+)}' : r'\$(\w+)').allMatches(path);
    if (wildcards.length > 1) {
      reporter.deprecatedReportErrorForNode(_code, arguments.first);
    }
  });
}