Skip to content

Commit c59e4c4

Browse files
committed
fix: suggested fixes
1 parent 330ebc3 commit c59e4c4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

copyloopvar.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func report(pass *analysis.Pass, assignStmt *ast.AssignStmt, right *ast.Ident, i
134134
Message: fmt.Sprintf(`The copy of the 'for' variable "%s" can be deleted (Go 1.22+)`, right.Name),
135135
}
136136

137-
if i == 1 && isSimpleAssignStmt(assignStmt, right) {
137+
if i == 0 && isSimpleAssignStmt(assignStmt, right) {
138138
diagnostic.SuggestedFixes = append(diagnostic.SuggestedFixes, analysis.SuggestedFix{
139139
TextEdits: []analysis.TextEdit{{
140140
Pos: assignStmt.Pos(),
@@ -157,5 +157,5 @@ func isSimpleAssignStmt(assignStmt *ast.AssignStmt, rhs *ast.Ident) bool {
157157
return false
158158
}
159159

160-
return rhs == lhs
160+
return rhs.Name == lhs.Name
161161
}

copyloopvar_test.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,23 @@ func TestAnalyzer(t *testing.T) {
3535
}
3636
}
3737

38-
analysistest.RunWithSuggestedFixes(t, analysistest.TestData(), analyzer, test.dir)
38+
results := analysistest.RunWithSuggestedFixes(t, analysistest.TestData(), analyzer, test.dir)
39+
40+
hasSuggestedFixes(t, results)
3941
})
4042
}
4143
}
44+
45+
func hasSuggestedFixes(t *testing.T, results []*analysistest.Result) {
46+
t.Helper()
47+
48+
for _, result := range results {
49+
for _, diagnostic := range result.Diagnostics {
50+
if len(diagnostic.SuggestedFixes) > 0 {
51+
return
52+
}
53+
}
54+
}
55+
56+
t.Errorf("no suggested fixes found")
57+
}

0 commit comments

Comments
 (0)