Skip to content

Commit a59959a

Browse files
committed
chore: lint
1 parent 1ba06de commit a59959a

File tree

7 files changed

+100
-99
lines changed

7 files changed

+100
-99
lines changed

internal/plugins/import/plugin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
package import_plugin
2-
const PLUGIN_NAME = "eslint-plugin-import"
2+
3+
const PLUGIN_NAME = "eslint-plugin-import"

internal/plugins/react_hooks/code_path_analysis/code_path.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type CodePath struct {
44
id string // An identifier
55
origin string // The type of code path origin
66
upper *CodePath // The code path of the upper function scope
7-
onLooped func(fromSegment *CodePathSegment, toSegment *CodePathSegment) // A callback funciton to notify looping
7+
onLooped func(fromSegment *CodePathSegment, toSegment *CodePathSegment) // A callback function to notify looping
88
childCodePaths []*CodePath // The code paths of nested function scopes
99
state *CodePathState // The state of the code path
1010
}

internal/plugins/react_hooks/code_path_analysis/fork_context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (fc *ForkContext) makeSegments(begin int, end int, create func(id string, a
102102

103103
segments := make([]*CodePathSegment, 0)
104104

105-
for i := 0; i < fc.count; i++ {
105+
for i := range fc.count {
106106
allPrevSegments := make([]*CodePathSegment, 0)
107107
for j := normalizedBegin; j <= normalizedEnd; j++ {
108108
allPrevSegments = append(allPrevSegments, list[j][i])
@@ -122,7 +122,7 @@ func (fc *ForkContext) mergeExtraSegments(segments []*CodePathSegment) []*CodePa
122122
merged := make([]*CodePathSegment, 0)
123123

124124
length := len(currentSegments) / 2
125-
for i := 0; i < length; i++ {
125+
for i := range length {
126126
segment := NewNextCodePathSegment(
127127
fc.idGenerator.Next(),
128128
[]*CodePathSegment{
@@ -185,7 +185,7 @@ func removeSegment(segments []*CodePathSegment, target *CodePathSegment) []*Code
185185
// If there is the "default" chunk before other cases, the order is different
186186
// between node's and running's.
187187
func RemoveConnection(prevSegments []*CodePathSegment, nextSegments []*CodePathSegment) {
188-
for i := 0; i < len(prevSegments); i++ {
188+
for i := range prevSegments {
189189
prevSegment := prevSegments[i]
190190
nextSegment := nextSegments[i]
191191

internal/plugins/react_hooks/code_path_analysis/loop_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (s *CodePathState) MakeWhileBody() {
193193
}
194194

195195
// Update state.
196-
if context.test != true {
196+
if !context.test {
197197
context.brokenForkContext.AddAll(choiceContext.falseForkContext)
198198
}
199199
forkContext.ReplaceHead(choiceContext.trueForkContext.MakeNext(0, -1))

internal/plugins/react_hooks/code_path_analysis/switch_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (s *CodePathState) PopSwitchContext() {
8080
}
8181

8282
// Pops the segment context stack until the entry segment.
83-
for i := 0; i < context.countForks; i++ {
83+
for range context.countForks {
8484
s.forkContext = s.forkContext.upper
8585
}
8686

internal/plugins/react_hooks/code_path_analysis/try_context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ func (s *CodePathState) MakeFinallyBlock() {
139139
// This segment will leave at the end of this finally block.
140140
segments := forkContext.MakeNext(-1, -1)
141141

142-
for i := 0; i < forkContext.count; i++ {
142+
for i := range forkContext.count {
143143
prevSegsOfLeavingSegment := []*CodePathSegment{headOfLeavingSegments[i]}
144144

145-
for j := 0; j < len(returned.segmentsList); j++ {
145+
for j := range len(returned.segmentsList) {
146146
prevSegsOfLeavingSegment = append(prevSegsOfLeavingSegment, returned.segmentsList[j][i])
147147
}
148-
for j := 0; j < len(thrown.segmentsList); j++ {
148+
for j := range len(thrown.segmentsList) {
149149
prevSegsOfLeavingSegment = append(prevSegsOfLeavingSegment, thrown.segmentsList[j][i])
150150
}
151151

internal/plugins/react_hooks/rules/rules_of_hooks/rules_of_hooks.go

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,10 @@ func isComponentName(name string) bool {
552552

553553
// Helper function to check if a function is a hook
554554
func isHook(node *ast.Node) bool {
555-
if node.Kind == ast.KindIdentifier {
555+
switch node.Kind {
556+
case ast.KindIdentifier:
556557
return isHookName(node.Text())
557-
} else if node.Kind == ast.KindPropertyAccessExpression {
558+
case ast.KindPropertyAccessExpression:
558559
name := node.AsPropertyAccessExpression().Name()
559560
if name == nil || !isHook(name) {
560561
return false
@@ -566,9 +567,8 @@ func isHook(node *ast.Node) bool {
566567
}
567568

568569
return isPascalCaseNameSpace(expr.AsIdentifier().Text)
569-
} else {
570-
return false
571570
}
571+
return false
572572
}
573573

574574
// Helper function to get function name from AST node
@@ -657,47 +657,47 @@ func isFunctionLike(node *ast.Node) bool {
657657
}
658658

659659
// 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+
// }
675675

676676
// 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+
// }
701701

702702
// Helper function to check if node is inside a class
703703
func isInsideClass(node *ast.Node) bool {
@@ -743,52 +743,52 @@ func isUseIdentifier(node *ast.Node) bool {
743743
}
744744

745745
// 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+
// }
792792

793793
// Helper function to check if node is at top level
794794
func isTopLevel(node *ast.Node) bool {

0 commit comments

Comments
 (0)