Skip to content

Commit 5f12303

Browse files
ldezuudashr
authored andcommitted
exportloopref: deprecation (golangci#4916)
1 parent edc66bd commit 5f12303

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+11
-92
lines changed

.golangci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,16 @@ linters:
106106
disable-all: true
107107
enable:
108108
- bodyclose
109+
- copyloopvar
109110
- depguard
110111
- dogsled
111112
- dupl
112113
- errcheck
113114
- errorlint
114-
- exportloopref
115115
- funlen
116116
- gocheckcompilerdirectives
117117
- gochecknoinits
118+
- gochecknoinits
118119
- goconst
119120
- gocritic
120121
- gocyclo
@@ -126,6 +127,7 @@ linters:
126127
- gosec
127128
- gosimple
128129
- govet
130+
- intrange
129131
- ineffassign
130132
- lll
131133
- misspell

pkg/commands/config_verify.go

-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ func printValidationDetail(cmd *cobra.Command, detail *jsonschema.Detailed) {
140140
}
141141

142142
for _, d := range detail.Errors {
143-
d := d
144143
printValidationDetail(cmd, &d)
145144
}
146145
}

pkg/commands/config_verify_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func Test_createSchemaURL(t *testing.T) {
6363
}
6464

6565
for _, test := range testCases {
66-
test := test
6766
t.Run(test.desc, func(t *testing.T) {
6867
t.Parallel()
6968

@@ -126,7 +125,6 @@ func Test_createSchemaURL_error(t *testing.T) {
126125
}
127126

128127
for _, test := range testCases {
129-
test := test
130128
t.Run(test.desc, func(t *testing.T) {
131129
t.Parallel()
132130

pkg/commands/internal/builder_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ func Test_sanitizeVersion(t *testing.T) {
4545
}
4646

4747
for _, test := range testCases {
48-
test := test
4948
t.Run(test.desc, func(t *testing.T) {
5049
t.Parallel()
5150

pkg/commands/internal/configuration_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func TestConfiguration_Validate(t *testing.T) {
4141
}
4242

4343
for _, test := range testCases {
44-
test := test
4544
t.Run(test.desc, func(t *testing.T) {
4645
t.Parallel()
4746

@@ -115,7 +114,6 @@ func TestConfiguration_Validate_error(t *testing.T) {
115114
}
116115

117116
for _, test := range testCases {
118-
test := test
119117
t.Run(test.desc, func(t *testing.T) {
120118
t.Parallel()
121119

pkg/config/config_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ func TestIsGoGreaterThanOrEqual(t *testing.T) {
7676
}
7777

7878
for _, test := range testCases {
79-
test := test
8079
t.Run(test.desc, func(t *testing.T) {
8180
t.Parallel()
8281

@@ -124,7 +123,6 @@ func Test_trimGoVersion(t *testing.T) {
124123
}
125124

126125
for _, test := range testCases {
127-
test := test
128126
t.Run(test.desc, func(t *testing.T) {
129127
t.Parallel()
130128

pkg/config/issues_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ func TestExcludeRule_Validate(t *testing.T) {
121121
}
122122

123123
for _, test := range testCases {
124-
test := test
125124
t.Run(test.desc, func(t *testing.T) {
126125
t.Parallel()
127126

@@ -194,7 +193,6 @@ func TestExcludeRule_Validate_error(t *testing.T) {
194193
}
195194

196195
for _, test := range testCases {
197-
test := test
198196
t.Run(test.desc, func(t *testing.T) {
199197
t.Parallel()
200198

pkg/config/linters_settings_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TestLintersSettings_Validate(t *testing.T) {
3333
}
3434

3535
for _, test := range testCases {
36-
test := test
3736
t.Run(test.desc, func(t *testing.T) {
3837
t.Parallel()
3938

@@ -74,7 +73,6 @@ func TestLintersSettings_Validate_error(t *testing.T) {
7473
}
7574

7675
for _, test := range testCases {
77-
test := test
7876
t.Run(test.desc, func(t *testing.T) {
7977
t.Parallel()
8078

@@ -112,7 +110,6 @@ func TestCustomLinterSettings_Validate(t *testing.T) {
112110
}
113111

114112
for _, test := range testCases {
115-
test := test
116113
t.Run(test.desc, func(t *testing.T) {
117114
t.Parallel()
118115

@@ -144,7 +141,6 @@ func TestCustomLinterSettings_Validate_error(t *testing.T) {
144141
}
145142

146143
for _, test := range testCases {
147-
test := test
148144
t.Run(test.desc, func(t *testing.T) {
149145
t.Parallel()
150146

@@ -181,7 +177,6 @@ func TestGovetSettings_Validate(t *testing.T) {
181177
}
182178

183179
for _, test := range testCases {
184-
test := test
185180
t.Run(test.desc, func(t *testing.T) {
186181
t.Parallel()
187182

@@ -224,7 +219,6 @@ func TestGovetSettings_Validate_error(t *testing.T) {
224219
}
225220

226221
for _, test := range testCases {
227-
test := test
228222
t.Run(test.desc, func(t *testing.T) {
229223
t.Parallel()
230224

pkg/config/linters_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func TestLinters_validateDisabledAndEnabledAtOneMoment(t *testing.T) {
4242
}
4343

4444
for _, test := range testCases {
45-
test := test
4645
t.Run(test.desc, func(t *testing.T) {
4746
t.Parallel()
4847

@@ -77,7 +76,6 @@ func TestLinters_validateDisabledAndEnabledAtOneMoment_error(t *testing.T) {
7776
}
7877

7978
for _, test := range testCases {
80-
test := test
8179
t.Run(test.desc, func(t *testing.T) {
8280
t.Parallel()
8381

@@ -138,7 +136,6 @@ func TestLinters_validateAllDisableEnableOptions(t *testing.T) {
138136
}
139137

140138
for _, test := range testCases {
141-
test := test
142139
t.Run(test.desc, func(t *testing.T) {
143140
t.Parallel()
144141

@@ -201,7 +198,6 @@ func TestLinters_validateAllDisableEnableOptions_error(t *testing.T) {
201198
}
202199

203200
for _, test := range testCases {
204-
test := test
205201
t.Run(test.desc, func(t *testing.T) {
206202
t.Parallel()
207203

pkg/config/output_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func TestOutput_Validate(t *testing.T) {
4242
}
4343

4444
for _, test := range testCases {
45-
test := test
4645
t.Run(test.desc, func(t *testing.T) {
4746
t.Parallel()
4847

@@ -95,7 +94,6 @@ func TestOutput_Validate_error(t *testing.T) {
9594
}
9695

9796
for _, test := range testCases {
98-
test := test
9997
t.Run(test.desc, func(t *testing.T) {
10098
t.Parallel()
10199

@@ -133,7 +131,6 @@ func TestOutputFormat_Validate(t *testing.T) {
133131
}
134132

135133
for _, test := range testCases {
136-
test := test
137134
t.Run(test.desc, func(t *testing.T) {
138135
t.Parallel()
139136

@@ -164,7 +161,6 @@ func TestOutputFormat_Validate_error(t *testing.T) {
164161
}
165162

166163
for _, test := range testCases {
167-
test := test
168164
t.Run(test.desc, func(t *testing.T) {
169165
t.Parallel()
170166

pkg/config/run_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func TestRun_Validate(t *testing.T) {
3838
}
3939

4040
for _, test := range testCases {
41-
test := test
4241
t.Run(test.desc, func(t *testing.T) {
4342
t.Parallel()
4443

@@ -64,7 +63,6 @@ func TestRun_Validate_error(t *testing.T) {
6463
}
6564

6665
for _, test := range testCases {
67-
test := test
6866
t.Run(test.desc, func(t *testing.T) {
6967
t.Parallel()
7068

pkg/config/severity_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func TestSeverity_Validate(t *testing.T) {
4848
}
4949

5050
for _, test := range testCases {
51-
test := test
5251
t.Run(test.desc, func(t *testing.T) {
5352
t.Parallel()
5453

@@ -96,7 +95,6 @@ func TestSeverity_Validate_error(t *testing.T) {
9695
}
9796

9897
for _, test := range testCases {
99-
test := test
10098
t.Run(test.desc, func(t *testing.T) {
10199
t.Parallel()
102100

@@ -194,7 +192,6 @@ func TestSeverityRule_Validate_error(t *testing.T) {
194192
}
195193

196194
for _, test := range testCases {
197-
test := test
198195
t.Run(test.desc, func(t *testing.T) {
199196
t.Parallel()
200197

pkg/goanalysis/pkgerrors/errors.go

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ func BuildIssuesFromIllTypedError(errs []error, lintCtx *linter.Context) ([]resu
2525
var other error
2626

2727
for _, err := range errs {
28-
err := err
29-
3028
var ill *IllTypedError
3129
if !errors.As(err, &ill) {
3230
if other == nil {

pkg/goanalysis/pkgerrors/extract_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func Test_stackCrusher(t *testing.T) {
4040
}
4141

4242
for _, test := range testCases {
43-
test := test
4443
t.Run(test.desc, func(t *testing.T) {
4544
t.Parallel()
4645

pkg/goanalysis/runner_loadingpackage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ func sizeOfReflectValueTreeBytes(rv reflect.Value, visitedPtrs map[uintptr]struc
475475
return sizeOfReflectValueTreeBytes(rv.Elem(), visitedPtrs)
476476
case reflect.Struct:
477477
ret := 0
478-
for i := 0; i < rv.NumField(); i++ {
478+
for i := range rv.NumField() {
479479
ret += sizeOfReflectValueTreeBytes(rv.Field(i), visitedPtrs)
480480
}
481481
return ret

pkg/goanalysis/runners.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context,
205205
wg.Add(workerCount)
206206

207207
pkgCh := make(chan *packages.Package, len(pkgs))
208-
for i := 0; i < workerCount; i++ {
208+
for range workerCount {
209209
go func() {
210210
defer wg.Done()
211211
for pkg := range pkgCh {

pkg/golinters/gocritic/gocritic_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ func Test_settingsWrapper_InferEnabledChecks(t *testing.T) {
262262
}
263263

264264
for _, tt := range cases {
265-
tt := tt
266265
t.Run(tt.name, func(t *testing.T) {
267266
t.Parallel()
268267

@@ -434,7 +433,6 @@ func Test_settingsWrapper_Validate(t *testing.T) {
434433
}
435434

436435
for _, tt := range cases {
437-
tt := tt
438436
t.Run(tt.name, func(t *testing.T) {
439437
t.Parallel()
440438

pkg/golinters/gosec/gosec_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ func Test_toGosecConfig(t *testing.T) {
5858
}
5959

6060
for _, test := range testCases {
61-
test := test
6261
t.Run(test.desc, func(t *testing.T) {
6362
t.Parallel()
6463

pkg/golinters/internal/diff.go

-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ func ExtractIssuesFromPatch(patch string, lintCtx *linter.Context, linterName st
242242
changes := p.parse(hunk)
243243

244244
for _, change := range changes {
245-
change := change // fix scope
246245
i := result.Issue{
247246
FromLinter: linterName,
248247
Pos: token.Position{

pkg/golinters/misspell/misspell_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ func Test_appendExtraWords_error(t *testing.T) {
8181
}
8282

8383
for _, test := range testCases {
84-
test := test
8584
t.Run(test.desc, func(t *testing.T) {
8685
t.Parallel()
8786

pkg/golinters/nolintlint/internal/nolintlint_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ func foo() {
209209
}
210210

211211
for _, test := range testCases {
212-
test := test
213212
t.Run(test.desc, func(t *testing.T) {
214213
t.Parallel()
215214

pkg/golinters/thelper/testdata/thelper.go

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func TestSubtestShouldNotBeChecked(t *testing.T) {
5252
}
5353

5454
for _, test := range testCases {
55-
test := test
5655
t.Run(test.desc, func(t *testing.T) {
5756
t.Parallel()
5857

pkg/lint/lintersdb/builder_linter.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
279279
WithSince("v1.28.0").
280280
WithPresets(linter.PresetBugs).
281281
WithLoadForGoAnalysis().
282-
WithURL("https://github.com/kyoh86/exportloopref"),
282+
WithURL("https://github.com/kyoh86/exportloopref").
283+
DeprecatedWarning("Since Go1.22 (loopvar) this linter is no longer relevant.", "v1.60.2", "copyloopvar"),
283284

284285
linter.NewConfig(forbidigo.New(&cfg.LintersSettings.Forbidigo)).
285286
WithSince("v1.34.0").

pkg/lint/lintersdb/builder_plugin_go.go

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ func (b *PluginGoBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
4343
continue
4444
}
4545

46-
settings := settings
47-
4846
lc, err := b.loadConfig(cfg, name, &settings)
4947
if err != nil {
5048
return nil, fmt.Errorf("unable to load custom analyzer %q: %s, %w", name, settings.Path, err)

pkg/lint/lintersdb/manager.go

-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ func (m *Manager) build(enabledByDefaultLinters []*linter.Config) map[string]*li
162162
// --presets can only add linters to default set
163163
for _, p := range m.cfg.Linters.Presets {
164164
for _, lc := range m.GetAllLinterConfigsForPreset(p) {
165-
lc := lc
166165
resultLintersSet[lc.Name()] = lc
167166
}
168167
}

pkg/lint/lintersdb/manager_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ func TestManager_build(t *testing.T) {
149149
}
150150

151151
for _, c := range cases {
152-
c := c
153152
t.Run(c.name, func(t *testing.T) {
154153
m, err := NewManager(logutils.NewStderrLog("skip"), &config.Config{Linters: c.cfg}, NewLinterBuilder())
155154
require.NoError(t, err)
@@ -304,7 +303,6 @@ func TestManager_combineGoAnalysisLinters(t *testing.T) {
304303
}
305304

306305
for _, test := range testCases {
307-
test := test
308306
t.Run(test.desc, func(t *testing.T) {
309307
t.Parallel()
310308

0 commit comments

Comments
 (0)