exportloopref: deprecation (#4916)

This commit is contained in:
Ludovic Fernandez 2024-08-17 13:41:10 +02:00 committed by GitHub
parent af298e1e82
commit 87dd8fe755
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
48 changed files with 11 additions and 92 deletions

View File

@ -106,15 +106,16 @@ linters:
disable-all: true
enable:
- bodyclose
- copyloopvar
- depguard
- dogsled
- dupl
- errcheck
- errorlint
- exportloopref
- funlen
- gocheckcompilerdirectives
- gochecknoinits
- gochecknoinits
- goconst
- gocritic
- gocyclo
@ -126,6 +127,7 @@ linters:
- gosec
- gosimple
- govet
- intrange
- ineffassign
- lll
- misspell

View File

@ -140,7 +140,6 @@ func printValidationDetail(cmd *cobra.Command, detail *jsonschema.Detailed) {
}
for _, d := range detail.Errors {
d := d
printValidationDetail(cmd, &d)
}
}

View File

@ -63,7 +63,6 @@ func Test_createSchemaURL(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -126,7 +125,6 @@ func Test_createSchemaURL_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -45,7 +45,6 @@ func Test_sanitizeVersion(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -41,7 +41,6 @@ func TestConfiguration_Validate(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -115,7 +114,6 @@ func TestConfiguration_Validate_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -76,7 +76,6 @@ func TestIsGoGreaterThanOrEqual(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -124,7 +123,6 @@ func Test_trimGoVersion(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -121,7 +121,6 @@ func TestExcludeRule_Validate(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -194,7 +193,6 @@ func TestExcludeRule_Validate_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -33,7 +33,6 @@ func TestLintersSettings_Validate(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -74,7 +73,6 @@ func TestLintersSettings_Validate_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -112,7 +110,6 @@ func TestCustomLinterSettings_Validate(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -144,7 +141,6 @@ func TestCustomLinterSettings_Validate_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -181,7 +177,6 @@ func TestGovetSettings_Validate(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -224,7 +219,6 @@ func TestGovetSettings_Validate_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -42,7 +42,6 @@ func TestLinters_validateDisabledAndEnabledAtOneMoment(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -77,7 +76,6 @@ func TestLinters_validateDisabledAndEnabledAtOneMoment_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -138,7 +136,6 @@ func TestLinters_validateAllDisableEnableOptions(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -201,7 +198,6 @@ func TestLinters_validateAllDisableEnableOptions_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -42,7 +42,6 @@ func TestOutput_Validate(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -95,7 +94,6 @@ func TestOutput_Validate_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -133,7 +131,6 @@ func TestOutputFormat_Validate(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -164,7 +161,6 @@ func TestOutputFormat_Validate_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -38,7 +38,6 @@ func TestRun_Validate(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -64,7 +63,6 @@ func TestRun_Validate_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -48,7 +48,6 @@ func TestSeverity_Validate(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -96,7 +95,6 @@ func TestSeverity_Validate_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -194,7 +192,6 @@ func TestSeverityRule_Validate_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -25,8 +25,6 @@ func BuildIssuesFromIllTypedError(errs []error, lintCtx *linter.Context) ([]resu
var other error
for _, err := range errs {
err := err
var ill *IllTypedError
if !errors.As(err, &ill) {
if other == nil {

View File

@ -40,7 +40,6 @@ func Test_stackCrusher(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -475,7 +475,7 @@ func sizeOfReflectValueTreeBytes(rv reflect.Value, visitedPtrs map[uintptr]struc
return sizeOfReflectValueTreeBytes(rv.Elem(), visitedPtrs)
case reflect.Struct:
ret := 0
for i := 0; i < rv.NumField(); i++ {
for i := range rv.NumField() {
ret += sizeOfReflectValueTreeBytes(rv.Field(i), visitedPtrs)
}
return ret

View File

@ -205,7 +205,7 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context,
wg.Add(workerCount)
pkgCh := make(chan *packages.Package, len(pkgs))
for i := 0; i < workerCount; i++ {
for range workerCount {
go func() {
defer wg.Done()
for pkg := range pkgCh {

View File

@ -262,7 +262,6 @@ func Test_settingsWrapper_InferEnabledChecks(t *testing.T) {
}
for _, tt := range cases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
@ -434,7 +433,6 @@ func Test_settingsWrapper_Validate(t *testing.T) {
}
for _, tt := range cases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

View File

@ -58,7 +58,6 @@ func Test_toGosecConfig(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -242,7 +242,6 @@ func ExtractIssuesFromPatch(patch string, lintCtx *linter.Context, linterName st
changes := p.parse(hunk)
for _, change := range changes {
change := change // fix scope
i := result.Issue{
FromLinter: linterName,
Pos: token.Position{

View File

@ -81,7 +81,6 @@ func Test_appendExtraWords_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -209,7 +209,6 @@ func foo() {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -52,7 +52,6 @@ func TestSubtestShouldNotBeChecked(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -278,7 +278,8 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithSince("v1.28.0").
WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/kyoh86/exportloopref"),
WithURL("https://github.com/kyoh86/exportloopref").
DeprecatedWarning("Since Go1.22 (loopvar) this linter is no longer relevant.", "v1.60.2", "copyloopvar"),
linter.NewConfig(forbidigo.New(&cfg.LintersSettings.Forbidigo)).
WithSince("v1.34.0").

View File

@ -43,8 +43,6 @@ func (b *PluginGoBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
continue
}
settings := settings
lc, err := b.loadConfig(cfg, name, &settings)
if err != nil {
return nil, fmt.Errorf("unable to load custom analyzer %q: %s, %w", name, settings.Path, err)

View File

@ -162,7 +162,6 @@ func (m *Manager) build(enabledByDefaultLinters []*linter.Config) map[string]*li
// --presets can only add linters to default set
for _, p := range m.cfg.Linters.Presets {
for _, lc := range m.GetAllLinterConfigsForPreset(p) {
lc := lc
resultLintersSet[lc.Name()] = lc
}
}

View File

@ -149,7 +149,6 @@ func TestManager_build(t *testing.T) {
}
for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
m, err := NewManager(logutils.NewStderrLog("skip"), &config.Config{Linters: c.cfg}, NewLinterBuilder())
require.NoError(t, err)
@ -304,7 +303,6 @@ func TestManager_combineGoAnalysisLinters(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -118,7 +118,6 @@ func TestValidator_Validate(t *testing.T) {
testCases = append(testCases, validatePresetsTestCases...)
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -139,7 +138,6 @@ func TestValidator_Validate_error(t *testing.T) {
testCases = append(testCases, validatePresetsErrorTestCases...)
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -158,7 +156,6 @@ func TestValidator_validateLintersNames(t *testing.T) {
v := NewValidator(m)
for _, test := range validateLintersNamesTestCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -175,7 +172,6 @@ func TestValidator_validateLintersNames_error(t *testing.T) {
v := NewValidator(m)
for _, test := range validateLintersNamesErrorTestCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -191,7 +187,6 @@ func TestValidator_validatePresets(t *testing.T) {
v := NewValidator(nil)
for _, test := range validatePresetsTestCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -205,7 +200,6 @@ func TestValidator_validatePresets_error(t *testing.T) {
v := NewValidator(nil)
for _, test := range validatePresetsErrorTestCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -37,7 +37,6 @@ func Test_buildArgs(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -115,7 +115,6 @@ func (r *Runner) Run(ctx context.Context, linters []*linter.Config) ([]result.Is
)
for _, lc := range linters {
lc := lc
sw.TrackStage(lc.Name(), func() {
linterIssues, err := r.runLinterSafe(ctx, r.lintCtx, lc)
if err != nil {
@ -189,7 +188,6 @@ func (r *Runner) processLintResults(inIssues []result.Issue) []result.Issue {
// finalize processors: logging, clearing, no heavy work here
for _, p := range r.Processors {
p := p
sw.TrackStage(p.Name(), func() {
p.Finish()
})
@ -220,7 +218,6 @@ func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, s
for _, p := range r.Processors {
var newIssues []result.Issue
var err error
p := p
sw.TrackStage(p.Name(), func() {
newIssues, err = p.Process(issues)
})

View File

@ -64,7 +64,6 @@ func TestPrinter_Print_stdout(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -82,7 +82,6 @@ path/to/fileb.go:300:9 another issue
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -110,7 +110,6 @@ path/to/fileb.go:300:9: another issue
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -45,7 +45,6 @@ func TestAutogeneratedExclude_isGeneratedFileLax_generated(t *testing.T) {
}
for _, comment := range comments {
comment := comment
t.Run(comment, func(t *testing.T) {
t.Parallel()
@ -64,7 +63,6 @@ func TestAutogeneratedExclude_isGeneratedFileLax_nonGenerated(t *testing.T) {
}
for _, comment := range comments {
comment := comment
t.Run(comment, func(t *testing.T) {
t.Parallel()
@ -95,7 +93,6 @@ func TestAutogeneratedExclude_isGeneratedFileStrict(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -183,7 +180,6 @@ func Test_shouldPassIssue(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -236,7 +232,6 @@ func Test_shouldPassIssue_error(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -64,7 +64,6 @@ func (p ExcludeRules) Process(issues []result.Issue) ([]result.Issue, error) {
return filterIssues(issues, func(issue *result.Issue) bool {
for _, rule := range p.rules {
rule := rule
if rule.match(issue, p.files, p.log) {
return false
}

View File

@ -111,7 +111,6 @@ func TestInvalidIssue_Process(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -183,7 +183,6 @@ func TestNolintInvalidLinterNameWithViolationOnTheSameLine(t *testing.T) {
func TestNolintAliases(t *testing.T) {
p := newTestNolintProcessor(getMockLog())
for _, line := range []int{47, 49, 51} {
line := line
t.Run(fmt.Sprintf("line-%d", line), func(t *testing.T) {
processAssertEmpty(t, p, newNolintFileIssue(line, "gosec"))
})

View File

@ -483,7 +483,6 @@ func TestSeverity_transform(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -48,7 +48,6 @@ func Test_absDirs(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -194,7 +194,7 @@ func mergeComparators(cmps []*comparator) (*comparator, error) {
return nil, errors.New("no comparator")
}
for i := 0; i < len(cmps)-1; i++ {
for i := range len(cmps) - 1 {
findComparatorTip(cmps[i]).SetNext(cmps[i+1])
}

View File

@ -79,8 +79,7 @@ type compareTestCase struct {
func testCompareValues(t *testing.T, cmp *comparator, name string, tests []compareTestCase) {
t.Parallel()
for i := 0; i < len(tests); i++ {
test := tests[i]
for i, test := range tests { //nolint:gocritic // To ignore rangeValCopy rule
t.Run(fmt.Sprintf("%s(%d)", name, i), func(t *testing.T) {
res := cmp.Compare(&test.a, &test.b)
assert.Equal(t, test.expected.String(), res.String())
@ -200,8 +199,7 @@ func TestNumericCompare(t *testing.T) {
t.Parallel()
for i := 0; i < len(tests); i++ {
test := tests[i]
for i, test := range tests {
t.Run(fmt.Sprintf("%s(%d)", "Numeric Compare", i), func(t *testing.T) {
res := numericCompare(test.a, test.b)
assert.Equal(t, test.expected.String(), res.String())
@ -267,7 +265,6 @@ func Test_mergeComparators(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -154,7 +154,7 @@ func formatDesc(desc string) string {
func hasSettings(name string) bool {
tp := reflect.TypeOf(config.LintersSettings{})
for i := 0; i < tp.NumField(); i++ {
for i := range tp.NumField() {
if strings.EqualFold(name, tp.Field(i).Name) {
return true
}

View File

@ -114,7 +114,6 @@ func TestEnabledLinters(t *testing.T) {
binPath := testshared.InstallGolangciLint(t)
for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()

View File

@ -144,7 +144,6 @@ func TestCgoWithIssues(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -242,7 +241,6 @@ func TestLineDirective(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -301,7 +299,6 @@ func TestLineDirectiveProcessedFiles(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -349,7 +346,6 @@ func TestSortedResults(t *testing.T) {
binPath := testshared.InstallGolangciLint(t)
for _, test := range testCases {
test := test
t.Run(test.opt, func(t *testing.T) {
t.Parallel()
@ -437,7 +433,6 @@ func TestConfigFileIsDetected(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -475,7 +470,6 @@ func TestEnableAllFastAndEnableCanCoexist(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
@ -559,7 +553,6 @@ func TestPathPrefix(t *testing.T) {
binPath := testshared.InstallGolangciLint(t)
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
testshared.NewRunnerBuilder(t).
WithArgs(test.args...).

View File

@ -124,7 +124,6 @@ func println(...interface{}) { println() } // want println:"found" "call of prin
}
for _, test := range testCases {
test := test
t.Run(test.filename, func(t *testing.T) {
t.Parallel()

View File

@ -72,7 +72,6 @@ func Test_evaluateBuildTags(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

View File

@ -56,8 +56,6 @@ func runFix(t *testing.T, extraArgs ...string) {
sources := setupTestFix(t)
for _, input := range sources {
input := input
t.Run(filepath.Base(input), func(t *testing.T) {
t.Parallel()

View File

@ -42,7 +42,6 @@ func RunTestSourcesFromDir(t *testing.T, dir string) {
log.SetLevel(logutils.LogLevelInfo)
for _, source := range sources {
source := source
t.Run(filepath.Base(source), func(subTest *testing.T) {
subTest.Parallel()

View File

@ -167,7 +167,6 @@ func TestRunnerBuilder_Runner(t *testing.T) {
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()