check method

  1. @override
void check(
  1. DcqRegistry registry
)

Implementation

@override
void check(DcqRegistry registry) {
  registry.addMethodInvocation((node) {
    if (!isHookCall(node.methodName.name)) return;

    var current = node.parent;
    while (current != null) {
      if (current is ClassDeclaration) {
        // If it's already a HookWidget, it's fine.
        if (isHookWidgetClass(current)) return;

        // Walk the resolved type hierarchy to check for widget base classes.
        final superType = current.extendsClause?.superclass.type;
        if (superType is InterfaceType) {
          if (_extendsAnyWidget(superType)) {
            reportAtNode(node);
          }
          return;
        }

        // Fallback to AST name when type is unresolved.
        final superName = current.extendsClause?.superclass.name.lexeme;
        if (superName != null && _widgetBaseClasses.contains(superName)) {
          reportAtNode(node);
        }
        return;
      }
      current = current.parent;
    }
  });
}