@@ -552,9 +552,10 @@ func isComponentName(name string) bool {
552
552
553
553
// Helper function to check if a function is a hook
554
554
func isHook (node * ast.Node ) bool {
555
- if node .Kind == ast .KindIdentifier {
555
+ switch node .Kind {
556
+ case ast .KindIdentifier :
556
557
return isHookName (node .Text ())
557
- } else if node . Kind == ast .KindPropertyAccessExpression {
558
+ case ast .KindPropertyAccessExpression :
558
559
name := node .AsPropertyAccessExpression ().Name ()
559
560
if name == nil || ! isHook (name ) {
560
561
return false
@@ -566,9 +567,8 @@ func isHook(node *ast.Node) bool {
566
567
}
567
568
568
569
return isPascalCaseNameSpace (expr .AsIdentifier ().Text )
569
- } else {
570
- return false
571
570
}
571
+ return false
572
572
}
573
573
574
574
// Helper function to get function name from AST node
@@ -657,47 +657,47 @@ func isFunctionLike(node *ast.Node) bool {
657
657
}
658
658
659
659
// Helper function to check if node is inside a loop
660
- func isInsideLoop (node * ast.Node ) bool {
661
- current := node .Parent
662
- for current != nil {
663
- kind := current .Kind
664
- if kind == ast .KindForStatement ||
665
- kind == ast .KindForInStatement ||
666
- kind == ast .KindForOfStatement ||
667
- kind == ast .KindWhileStatement ||
668
- kind == ast .KindDoStatement {
669
- return true
670
- }
671
- current = current .Parent
672
- }
673
- return false
674
- }
660
+ // func isInsideLoop(node *ast.Node) bool {
661
+ // current := node.Parent
662
+ // for current != nil {
663
+ // kind := current.Kind
664
+ // if kind == ast.KindForStatement ||
665
+ // kind == ast.KindForInStatement ||
666
+ // kind == ast.KindForOfStatement ||
667
+ // kind == ast.KindWhileStatement ||
668
+ // kind == ast.KindDoStatement {
669
+ // return true
670
+ // }
671
+ // current = current.Parent
672
+ // }
673
+ // return false
674
+ // }
675
675
676
676
// Helper function to check if node is inside a conditional
677
- func isInsideConditional (node * ast.Node ) bool {
678
- current := node .Parent
679
- for current != nil {
680
- kind := current .Kind
681
- if kind == ast .KindIfStatement ||
682
- kind == ast .KindConditionalExpression {
683
- return true
684
- }
685
- // TODO: Check for logical operators (&& || ??)
686
- if kind == ast .KindBinaryExpression {
687
- binExpr := current .AsBinaryExpression ()
688
- if binExpr != nil {
689
- op := binExpr .OperatorToken .Kind
690
- if op == ast .KindAmpersandAmpersandToken ||
691
- op == ast .KindBarBarToken ||
692
- op == ast .KindQuestionQuestionToken {
693
- return true
694
- }
695
- }
696
- }
697
- current = current .Parent
698
- }
699
- return false
700
- }
677
+ // func isInsideConditional(node *ast.Node) bool {
678
+ // current := node.Parent
679
+ // for current != nil {
680
+ // kind := current.Kind
681
+ // if kind == ast.KindIfStatement ||
682
+ // kind == ast.KindConditionalExpression {
683
+ // return true
684
+ // }
685
+ // // TODO: Check for logical operators (&& || ??)
686
+ // if kind == ast.KindBinaryExpression {
687
+ // binExpr := current.AsBinaryExpression()
688
+ // if binExpr != nil {
689
+ // op := binExpr.OperatorToken.Kind
690
+ // if op == ast.KindAmpersandAmpersandToken ||
691
+ // op == ast.KindBarBarToken ||
692
+ // op == ast.KindQuestionQuestionToken {
693
+ // return true
694
+ // }
695
+ // }
696
+ // }
697
+ // current = current.Parent
698
+ // }
699
+ // return false
700
+ // }
701
701
702
702
// Helper function to check if node is inside a class
703
703
func isInsideClass (node * ast.Node ) bool {
@@ -743,52 +743,52 @@ func isUseIdentifier(node *ast.Node) bool {
743
743
}
744
744
745
745
// Helper function to check if call expression is a hook call
746
- func isHookCall (node * ast.Node ) (bool , string ) {
747
- if node .Kind != ast .KindCallExpression {
748
- return false , ""
749
- }
750
-
751
- callExpr := node .AsCallExpression ()
752
- if callExpr == nil {
753
- return false , ""
754
- }
755
-
756
- // Get the callee and extract the hook name
757
- // Handle different call patterns:
758
- // - useHook()
759
- // - React.useHook()
760
- // - obj.useHook()
761
- callee := callExpr .Expression
762
- if callee == nil {
763
- return false , ""
764
- }
765
-
766
- switch callee .Kind {
767
- case ast .KindIdentifier :
768
- // Direct call: useHook()
769
- identifier := callee .AsIdentifier ()
770
- if identifier != nil {
771
- name := scanner .GetTextOfNode (& identifier .Node )
772
- if isHookName (name ) {
773
- return true , name
774
- }
775
- }
776
- case ast .KindPropertyAccessExpression :
777
- // Property access: React.useHook(), obj.useHook()
778
- propAccess := callee .AsPropertyAccessExpression ()
779
- if propAccess != nil {
780
- nameNode := propAccess .Name ()
781
- if nameNode != nil {
782
- name := scanner .GetTextOfNode (nameNode )
783
- if isHookName (name ) {
784
- return true , name
785
- }
786
- }
787
- }
788
- }
789
-
790
- return false , ""
791
- }
746
+ // func isHookCall(node *ast.Node) (bool, string) {
747
+ // if node.Kind != ast.KindCallExpression {
748
+ // return false, ""
749
+ // }
750
+
751
+ // callExpr := node.AsCallExpression()
752
+ // if callExpr == nil {
753
+ // return false, ""
754
+ // }
755
+
756
+ // // Get the callee and extract the hook name
757
+ // // Handle different call patterns:
758
+ // // - useHook()
759
+ // // - React.useHook()
760
+ // // - obj.useHook()
761
+ // callee := callExpr.Expression
762
+ // if callee == nil {
763
+ // return false, ""
764
+ // }
765
+
766
+ // switch callee.Kind {
767
+ // case ast.KindIdentifier:
768
+ // // Direct call: useHook()
769
+ // identifier := callee.AsIdentifier()
770
+ // if identifier != nil {
771
+ // name := scanner.GetTextOfNode(&identifier.Node)
772
+ // if isHookName(name) {
773
+ // return true, name
774
+ // }
775
+ // }
776
+ // case ast.KindPropertyAccessExpression:
777
+ // // Property access: React.useHook(), obj.useHook()
778
+ // propAccess := callee.AsPropertyAccessExpression()
779
+ // if propAccess != nil {
780
+ // nameNode := propAccess.Name()
781
+ // if nameNode != nil {
782
+ // name := scanner.GetTextOfNode(nameNode)
783
+ // if isHookName(name) {
784
+ // return true, name
785
+ // }
786
+ // }
787
+ // }
788
+ // }
789
+
790
+ // return false, ""
791
+ // }
792
792
793
793
// Helper function to check if node is at top level
794
794
func isTopLevel (node * ast.Node ) bool {
0 commit comments