Skip to content

Commit 73f43d6

Browse files
mpywclaude
andcommitted
refactor: simplify identIsDeriverCall using existing helpers
Replace manual file iteration with VarFromIdent and FindCallExprAssignment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b18490c commit 73f43d6

File tree

1 file changed

+9
-45
lines changed

1 file changed

+9
-45
lines changed

internal/patterns/arg_is_deriver_call.go

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -51,56 +51,20 @@ func (p *ArgIsDeriverCall) argIsDeriverCall(cctx *context.CheckContext, expr ast
5151

5252
// identIsDeriverCall checks if a variable holds a deriver call result.
5353
func (p *ArgIsDeriverCall) identIsDeriverCall(cctx *context.CheckContext, ident *ast.Ident) bool {
54-
// Try to trace the variable assignment
55-
// This is a simplified check - just look for direct assignments
56-
obj := cctx.Pass.TypesInfo.ObjectOf(ident)
57-
if obj == nil {
54+
v := cctx.VarFromIdent(ident)
55+
if v == nil {
5856
return false
5957
}
6058

61-
// Find assignments to this variable
62-
for _, f := range cctx.Pass.Files {
63-
var found bool
64-
ast.Inspect(f, func(n ast.Node) bool {
65-
if found {
66-
return false
67-
}
68-
69-
assign, ok := n.(*ast.AssignStmt)
70-
if !ok {
71-
return true
72-
}
73-
74-
for i, lhs := range assign.Lhs {
75-
lhsIdent, ok := lhs.(*ast.Ident)
76-
if !ok {
77-
continue
78-
}
79-
if cctx.Pass.TypesInfo.ObjectOf(lhsIdent) != obj {
80-
continue
81-
}
82-
if i >= len(assign.Rhs) {
83-
continue
84-
}
85-
86-
// Check if RHS is a deriver call
87-
if call, ok := assign.Rhs[i].(*ast.CallExpr); ok {
88-
fn := cctx.ExtractCallFunc(call)
89-
if fn != nil && p.Matcher.MatchesFunc(fn) {
90-
found = true
91-
return false
92-
}
93-
}
94-
}
95-
return true
96-
})
97-
98-
if found {
99-
return true
100-
}
59+
// Find call expression assigned to this variable
60+
call := cctx.FindCallExprAssignment(v, ident.Pos())
61+
if call == nil {
62+
return false
10163
}
10264

103-
return false
65+
// Check if RHS is a deriver call
66+
fn := cctx.ExtractCallFunc(call)
67+
return fn != nil && p.Matcher.MatchesFunc(fn)
10468
}
10569

10670
// Message formats the error message for DoAsync-style methods.

0 commit comments

Comments
 (0)