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 is the package that *defines* the @unsafeOrError
  // primitives. Its own implementation legitimately calls them — flagging
  // those would force every internal Sync.okValue/Async.okValue/... to be
  // wrapped in UNSAFE(...), which adds runtime cost and visual noise for no
  // safety benefit. The rule is for *consumers*, not the implementation.
  if (context.pubspec.name == 'df_safer_dart') return;

  context.registry.addMethodInvocation((node) {
    _report(node, node.methodName.element, reporter);
  });

  // Catches unsafe constructors such as `Async.ok(...)` /
  // `Resolvable.result(...)` — these are not MethodInvocations.
  context.registry.addInstanceCreationExpression((node) {
    _report(node, node.constructorName.element, reporter);
  });

  // Catches unsafe getters/static fields accessed as `obj.unsafeGetter`
  // or `Class.unsafeStatic`.
  context.registry.addPropertyAccess((node) {
    _report(node, node.propertyName.element, reporter);
  });

  // Catches `prefix.unsafeMember` patterns (prefixed identifier) — e.g.,
  // a static field reference, or a getter chain like
  // `obj.unsafeGetter.subProp` where the PrefixedIdentifier is the target
  // of an outer PropertyAccess. The identifier's element filters out
  // non-member references (class refs, library prefixes), so this is safe.
  context.registry.addPrefixedIdentifier((node) {
    _report(node, node.identifier.element, reporter);
  });
}