run method

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

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,
) {
  // df_safer_dart implements the abstractions whose @noFutures annotations
  // this rule enforces; its internals legitimately bridge Futures into the
  // safe types and must be exempt. The rule is for *consumers*.
  if (context.pubspec.name == 'df_safer_dart') return;

  context.registry.addFunctionDeclaration((node) {
    if (isDirectlyAnnotatedByText(node, shortName, longName)) {
      _checkBody(
        body: node.functionExpression.body,
        returnType:
            node.functionExpression.declaredFragment?.element.returnType,
        reporter: reporter,
        errorNode: node,
      );
    }
  });

  context.registry.addMethodDeclaration((node) {
    if (isDirectlyAnnotatedByText(node, shortName, longName)) {
      _checkBody(
        body: node.body,
        returnType: node.declaredFragment?.element.returnType,
        reporter: reporter,
        errorNode: node,
      );
    }
  });

  context.registry.addFunctionExpression((node) {
    if (node.parent is FunctionDeclaration) return;

    final paramElement = node.correspondingParameter;
    if (paramElement != null && _checker.hasAnnotationOf(paramElement)) {
      _checkBody(
        body: node.body,
        returnType: node.declaredFragment?.element.returnType,
        reporter: reporter,
        errorNode: node,
      );
    }
  });
}