registerNodeProcessors method

  1. @override
void registerNodeProcessors(
  1. RuleVisitorRegistry registry,
  2. RuleContext context
)

Registers node processors in the given registry.

The node processors may use the provided context to access information that is not available from the AST nodes or their associated elements.

Implementation

@override
void registerNodeProcessors(
  RuleVisitorRegistry registry,
  RuleContext 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 (isInDfSaferDartPackage(context)) return;

  final visitor = _Visitor(this);
  registry.addMethodInvocation(this, visitor);
  // Catches unsafe constructors such as `Async.ok(...)` /
  // `Resolvable.result(...)` — these are not MethodInvocations.
  registry.addInstanceCreationExpression(this, visitor);
  // Catches unsafe getters/static fields accessed as `obj.unsafeGetter`
  // or `Class.unsafeStatic`.
  registry.addPropertyAccess(this, visitor);
  // 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.
  registry.addPrefixedIdentifier(this, visitor);
}