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,
) async {
  final annotation = await getFirebaseRulesAnnotation(resolver);
  // This isn't a rules file
  if (annotation == null) return;

  context.registry.addMethodInvocation((node) {
    if (node.childEntities.length != 2) return;
    final functionName = node.childEntities.first;
    if (functionName is! SimpleIdentifier) return;

    final functions = annotation
        .getField('functions')
        ?.toListValue()
        ?.map((e) => e.toFunctionValue()!.name);
    if (functions != null && functions.contains(functionName.name)) {
      return;
    }

    reporter.atNode(functionName, _code);
  });
}