From 8dae415e2bfe21612014baa41f5827138c39ec28 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 23 Jan 2025 00:23:03 +0100 Subject: [PATCH] feat: deprecation step 2 of exportloopref --- pkg/golinters/exportloopref/exportloopref.go | 19 ------ .../exportloopref_integration_test.go | 11 ---- .../exportloopref/testdata/exportloopref.go | 46 ------------- .../testdata/exportloopref_cgo.go | 65 ------------------- pkg/lint/lintersdb/builder_linter.go | 5 +- 5 files changed, 2 insertions(+), 144 deletions(-) delete mode 100644 pkg/golinters/exportloopref/exportloopref.go delete mode 100644 pkg/golinters/exportloopref/exportloopref_integration_test.go delete mode 100644 pkg/golinters/exportloopref/testdata/exportloopref.go delete mode 100644 pkg/golinters/exportloopref/testdata/exportloopref_cgo.go diff --git a/pkg/golinters/exportloopref/exportloopref.go b/pkg/golinters/exportloopref/exportloopref.go deleted file mode 100644 index e232f8045d3f..000000000000 --- a/pkg/golinters/exportloopref/exportloopref.go +++ /dev/null @@ -1,19 +0,0 @@ -package exportloopref - -import ( - "github.com/kyoh86/exportloopref" - "golang.org/x/tools/go/analysis" - - "github.com/golangci/golangci-lint/pkg/goanalysis" -) - -func New() *goanalysis.Linter { - a := exportloopref.Analyzer - - return goanalysis.NewLinter( - a.Name, - a.Doc, - []*analysis.Analyzer{a}, - nil, - ).WithLoadMode(goanalysis.LoadModeTypesInfo) -} diff --git a/pkg/golinters/exportloopref/exportloopref_integration_test.go b/pkg/golinters/exportloopref/exportloopref_integration_test.go deleted file mode 100644 index e2696afe9e4f..000000000000 --- a/pkg/golinters/exportloopref/exportloopref_integration_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package exportloopref - -import ( - "testing" - - "github.com/golangci/golangci-lint/test/testshared/integration" -) - -func TestFromTestdata(t *testing.T) { - integration.RunTestdata(t) -} diff --git a/pkg/golinters/exportloopref/testdata/exportloopref.go b/pkg/golinters/exportloopref/testdata/exportloopref.go deleted file mode 100644 index 2d6b6aa36a37..000000000000 --- a/pkg/golinters/exportloopref/testdata/exportloopref.go +++ /dev/null @@ -1,46 +0,0 @@ -//golangcitest:args -Eexportloopref -package testdata - -import "fmt" - -func dummyFunction() { - var array [4]*int - var slice []*int - var ref *int - var str struct{ x *int } - - fmt.Println("loop expecting 10, 11, 12, 13") - for i, p := range []int{10, 11, 12, 13} { - printp(&p) - slice = append(slice, &p) // want "exporting a pointer for the loop variable p" - array[i] = &p // want "exporting a pointer for the loop variable p" - if i%2 == 0 { - ref = &p // want "exporting a pointer for the loop variable p" - str.x = &p // want "exporting a pointer for the loop variable p" - } - var vStr struct{ x *int } - var vArray [4]*int - var v *int - if i%2 == 0 { - v = &p - vArray[1] = &p - vStr.x = &p - } - _ = v - } - - fmt.Println(`slice expecting "10, 11, 12, 13" but "13, 13, 13, 13"`) - for _, p := range slice { - printp(p) - } - fmt.Println(`array expecting "10, 11, 12, 13" but "13, 13, 13, 13"`) - for _, p := range array { - printp(p) - } - fmt.Println(`captured value expecting "12" but "13"`) - printp(ref) -} - -func printp(p *int) { - fmt.Println(*p) -} diff --git a/pkg/golinters/exportloopref/testdata/exportloopref_cgo.go b/pkg/golinters/exportloopref/testdata/exportloopref_cgo.go deleted file mode 100644 index 22d0a2bdcc98..000000000000 --- a/pkg/golinters/exportloopref/testdata/exportloopref_cgo.go +++ /dev/null @@ -1,65 +0,0 @@ -//golangcitest:args -Eexportloopref -package testdata - -/* - #include - #include - - void myprint(char* s) { - printf("%d\n", s); - } -*/ -import "C" - -import ( - "fmt" - "unsafe" -) - -func _() { - cs := C.CString("Hello from stdio\n") - C.myprint(cs) - C.free(unsafe.Pointer(cs)) -} - -func dummyFunction() { - var array [4]*int - var slice []*int - var ref *int - var str struct{ x *int } - - fmt.Println("loop expecting 10, 11, 12, 13") - for i, p := range []int{10, 11, 12, 13} { - printp(&p) - slice = append(slice, &p) // want "exporting a pointer for the loop variable p" - array[i] = &p // want "exporting a pointer for the loop variable p" - if i%2 == 0 { - ref = &p // want "exporting a pointer for the loop variable p" - str.x = &p // want "exporting a pointer for the loop variable p" - } - var vStr struct{ x *int } - var vArray [4]*int - var v *int - if i%2 == 0 { - v = &p - vArray[1] = &p - vStr.x = &p - } - _ = v - } - - fmt.Println(`slice expecting "10, 11, 12, 13" but "13, 13, 13, 13"`) - for _, p := range slice { - printp(p) - } - fmt.Println(`array expecting "10, 11, 12, 13" but "13, 13, 13, 13"`) - for _, p := range array { - printp(p) - } - fmt.Println(`captured value expecting "12" but "13"`) - printp(ref) -} - -func printp(p *int) { - fmt.Println(*p) -} diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index beda9e3c76b6..ee05a75c7e29 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -25,7 +25,6 @@ import ( "github.com/golangci/golangci-lint/pkg/golinters/errorlint" "github.com/golangci/golangci-lint/pkg/golinters/exhaustive" "github.com/golangci/golangci-lint/pkg/golinters/exhaustruct" - "github.com/golangci/golangci-lint/pkg/golinters/exportloopref" "github.com/golangci/golangci-lint/pkg/golinters/exptostd" "github.com/golangci/golangci-lint/pkg/golinters/fatcontext" "github.com/golangci/golangci-lint/pkg/golinters/forbidigo" @@ -278,12 +277,12 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithLoadForGoAnalysis(). WithURL("https://github.com/GaijinEntertainment/go-exhaustruct"), - linter.NewConfig(exportloopref.New()). + linter.NewConfig(linter.NewNoopDeprecated("exportloopref", cfg, linter.DeprecationError)). WithSince("v1.28.0"). WithPresets(linter.PresetBugs). WithLoadForGoAnalysis(). WithURL("https://github.com/kyoh86/exportloopref"). - DeprecatedWarning("Since Go1.22 (loopvar) this linter is no longer relevant.", "v1.60.2", "copyloopvar"), + DeprecatedError("Since Go1.22 (loopvar) this linter is no longer relevant.", "v1.60.2", "copyloopvar"), linter.NewConfig(exptostd.New()). WithSince("v1.63.0").