From ca83ea00ee5505b83d9f2a3fcd707828fe77745a Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 26 Dec 2024 23:42:31 +0100 Subject: [PATCH 1/5] feat: add exptostd linter --- .golangci.next.reference.yml | 2 + go.mod | 1 + go.sum | 2 + jsonschema/golangci.next.jsonschema.json | 1 + pkg/golinters/exptostd/exptostd.go | 19 +++ .../exptostd/exptostd_integration_test.go | 11 ++ pkg/golinters/exptostd/testdata/exptostd.go | 85 ++++++++++++++ .../exptostd/testdata/exptostd_cgo.go | 102 +++++++++++++++++ .../exptostd/testdata/exptostd_go123.go | 91 +++++++++++++++ .../exptostd/testdata/exptostd_go123_cgo.go | 108 ++++++++++++++++++ pkg/golinters/exptostd/testdata/go.mod | 5 + pkg/golinters/exptostd/testdata/go.sum | 2 + pkg/lint/lintersdb/builder_linter.go | 7 ++ 13 files changed, 436 insertions(+) create mode 100644 pkg/golinters/exptostd/exptostd.go create mode 100644 pkg/golinters/exptostd/exptostd_integration_test.go create mode 100644 pkg/golinters/exptostd/testdata/exptostd.go create mode 100644 pkg/golinters/exptostd/testdata/exptostd_cgo.go create mode 100644 pkg/golinters/exptostd/testdata/exptostd_go123.go create mode 100644 pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go create mode 100644 pkg/golinters/exptostd/testdata/go.mod create mode 100644 pkg/golinters/exptostd/testdata/go.sum diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index b8445c5591eb..e49e9f879c9a 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -35,6 +35,7 @@ linters: - exhaustive - exhaustruct - exportloopref + - exptostd - fatcontext - forbidigo - forcetypeassert @@ -153,6 +154,7 @@ linters: - exhaustive - exhaustruct - exportloopref + - exptostd - fatcontext - forbidigo - forcetypeassert diff --git a/go.mod b/go.mod index 89100b2ade66..5efb93b6c2e0 100644 --- a/go.mod +++ b/go.mod @@ -65,6 +65,7 @@ require ( github.com/kunwardeep/paralleltest v1.0.10 github.com/kyoh86/exportloopref v0.1.11 github.com/lasiar/canonicalheader v1.1.2 + github.com/ldez/exptostd v0.1.0 github.com/ldez/gomoddirectives v0.6.0 github.com/ldez/grignotin v0.7.0 github.com/ldez/tagliatelle v0.7.1 diff --git a/go.sum b/go.sum index fe4fe0f80910..c3f84c238351 100644 --- a/go.sum +++ b/go.sum @@ -353,6 +353,8 @@ github.com/kyoh86/exportloopref v0.1.11 h1:1Z0bcmTypkL3Q4k+IDHMWTcnCliEZcaPiIe0/ github.com/kyoh86/exportloopref v0.1.11/go.mod h1:qkV4UF1zGl6EkF1ox8L5t9SwyeBAZ3qLMd6up458uqA= github.com/lasiar/canonicalheader v1.1.2 h1:vZ5uqwvDbyJCnMhmFYimgMZnJMjwljN5VGY0VKbMXb4= github.com/lasiar/canonicalheader v1.1.2/go.mod h1:qJCeLFS0G/QlLQ506T+Fk/fWMa2VmBUiEI2cuMK4djI= +github.com/ldez/exptostd v0.1.0 h1:/QkFfYxGpr8z1w7/BxBC49vm/kWLX5wi3TSxWC/DpVI= +github.com/ldez/exptostd v0.1.0/go.mod h1:iZBRYaUmcW5jwCR3KROEZ1KivQQp6PHXbDPk9hqJKCQ= github.com/ldez/gomoddirectives v0.6.0 h1:Jyf1ZdTeiIB4dd+2n4qw+g4aI9IJ6JyfOZ8BityWvnA= github.com/ldez/gomoddirectives v0.6.0/go.mod h1:TuwOGYoPAoENDWQpe8DMqEm5nIfjrxZXmxX/CExWyZ4= github.com/ldez/grignotin v0.7.0 h1:vh0dI32WhHaq6LLPZ38g7WxXuZ1+RzyrJ7iPG9JMa8c= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 6553bc369cea..4d94d0674f65 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -350,6 +350,7 @@ "exhaustive", "exhaustruct", "exportloopref", + "exptostd", "fatcontext", "forbidigo", "forcetypeassert", diff --git a/pkg/golinters/exptostd/exptostd.go b/pkg/golinters/exptostd/exptostd.go new file mode 100644 index 000000000000..2de8ea98c2b8 --- /dev/null +++ b/pkg/golinters/exptostd/exptostd.go @@ -0,0 +1,19 @@ +package exptostd + +import ( + "github.com/ldez/exptostd" + "golang.org/x/tools/go/analysis" + + "github.com/golangci/golangci-lint/pkg/goanalysis" +) + +func New() *goanalysis.Linter { + a := exptostd.NewAnalyzer() + + return goanalysis.NewLinter( + a.Name, + a.Doc, + []*analysis.Analyzer{a}, + nil, + ).WithLoadMode(goanalysis.LoadModeTypesInfo) +} diff --git a/pkg/golinters/exptostd/exptostd_integration_test.go b/pkg/golinters/exptostd/exptostd_integration_test.go new file mode 100644 index 000000000000..b9b291add7ff --- /dev/null +++ b/pkg/golinters/exptostd/exptostd_integration_test.go @@ -0,0 +1,11 @@ +package exptostd + +import ( + "testing" + + "github.com/golangci/golangci-lint/test/testshared/integration" +) + +func TestFromTestdata(t *testing.T) { + integration.RunTestdata(t) +} diff --git a/pkg/golinters/exptostd/testdata/exptostd.go b/pkg/golinters/exptostd/testdata/exptostd.go new file mode 100644 index 000000000000..53f0d303bb65 --- /dev/null +++ b/pkg/golinters/exptostd/testdata/exptostd.go @@ -0,0 +1,85 @@ +//golangcitest:args -Eexptostd +package testdata + +import ( + "fmt" + + "golang.org/x/exp/maps" + "golang.org/x/exp/slices" +) + +func _(m, a map[string]string) { + maps.Clone(m) // want `golang.org/x/exp/maps.Clone\(\) can be replaced by maps.Clone\(\)` + + maps.Equal(m, a) // want `golang.org/x/exp/maps.Equal\(\) can be replaced by maps.Equal\(\)` + + maps.EqualFunc(m, a, func(i, j string) bool { // want `golang.org/x/exp/maps.EqualFunc\(\) can be replaced by maps.EqualFunc\(\)` + return true + }) + + maps.Copy(m, a) // want `golang.org/x/exp/maps.Copy\(\) can be replaced by maps.Copy\(\)` + + maps.DeleteFunc(m, func(_, _ string) bool { // want `golang.org/x/exp/maps.DeleteFunc\(\) can be replaced by maps.DeleteFunc\(\)` + return true + }) + + maps.Clear(m) // want `golang.org/x/exp/maps.Clear\(\) can be replaced by clear\(\)` + + fmt.Println("Hello") +} + +func _(a, b []string) { + slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` + slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + return true + }) + slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` + slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + return 0 + }) + slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` + slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + return true + }) + slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` + slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + return true + }) + slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` + slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` + slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + return true + }) + slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` + slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` + slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` + slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + return true + }) + slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` + slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` + slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` + slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` + slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + return 0 + }) + slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + return 0 + }) + slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` + slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + return 0 + }) + slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` + slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + return 0 + }) + slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` + slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + return 0 + }) + slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + return 0 + }) +} diff --git a/pkg/golinters/exptostd/testdata/exptostd_cgo.go b/pkg/golinters/exptostd/testdata/exptostd_cgo.go new file mode 100644 index 000000000000..cdb7aa4fbf68 --- /dev/null +++ b/pkg/golinters/exptostd/testdata/exptostd_cgo.go @@ -0,0 +1,102 @@ +//golangcitest:args -Eexptostd +package testdata + +/* + #include + #include + + void myprint(char* s) { + printf("%d\n", s); + } +*/ +import "C" + +import ( + "fmt" + "unsafe" + + "golang.org/x/exp/maps" + "golang.org/x/exp/slices" +) + +func _() { + cs := C.CString("Hello from stdio\n") + C.myprint(cs) + C.free(unsafe.Pointer(cs)) +} + +func _(m, a map[string]string) { + maps.Clone(m) // want `golang.org/x/exp/maps.Clone\(\) can be replaced by maps.Clone\(\)` + + maps.Equal(m, a) // want `golang.org/x/exp/maps.Equal\(\) can be replaced by maps.Equal\(\)` + + maps.EqualFunc(m, a, func(i, j string) bool { // want `golang.org/x/exp/maps.EqualFunc\(\) can be replaced by maps.EqualFunc\(\)` + return true + }) + + maps.Copy(m, a) // want `golang.org/x/exp/maps.Copy\(\) can be replaced by maps.Copy\(\)` + + maps.DeleteFunc(m, func(_, _ string) bool { // want `golang.org/x/exp/maps.DeleteFunc\(\) can be replaced by maps.DeleteFunc\(\)` + return true + }) + + maps.Clear(m) // want `golang.org/x/exp/maps.Clear\(\) can be replaced by clear\(\)` + + fmt.Println("Hello") +} + +func _(a, b []string) { + slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` + slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + return true + }) + slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` + slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + return 0 + }) + slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` + slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + return true + }) + slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` + slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + return true + }) + slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` + slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` + slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + return true + }) + slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` + slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` + slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` + slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + return true + }) + slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` + slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` + slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` + slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` + slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + return 0 + }) + slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + return 0 + }) + slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` + slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + return 0 + }) + slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` + slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + return 0 + }) + slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` + slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + return 0 + }) + slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + return 0 + }) +} diff --git a/pkg/golinters/exptostd/testdata/exptostd_go123.go b/pkg/golinters/exptostd/testdata/exptostd_go123.go new file mode 100644 index 000000000000..4a997eca5961 --- /dev/null +++ b/pkg/golinters/exptostd/testdata/exptostd_go123.go @@ -0,0 +1,91 @@ +//go:build go1.23 + +//golangcitest:args -Eexptostd +package testdata + +import ( + "fmt" + + "golang.org/x/exp/maps" + "golang.org/x/exp/slices" +) + +func _(m, a map[string]string) { + maps.Clone(m) // want `golang.org/x/exp/maps.Clone\(\) can be replaced by maps.Clone\(\)` + + maps.Keys(m) // want `golang.org/x/exp/maps.Keys\(\) can be replaced by slices.Collect\(maps.Keys\(\)\)` + + maps.Values(m) // want `golang.org/x/exp/maps.Values\(\) can be replaced by slices.Collect\(maps.Keys\(\)\)` + + maps.Equal(m, a) // want `golang.org/x/exp/maps.Equal\(\) can be replaced by maps.Equal\(\)` + + maps.EqualFunc(m, a, func(i, j string) bool { // want `golang.org/x/exp/maps.EqualFunc\(\) can be replaced by maps.EqualFunc\(\)` + return true + }) + + maps.Copy(m, a) // want `golang.org/x/exp/maps.Copy\(\) can be replaced by maps.Copy\(\)` + + maps.DeleteFunc(m, func(_, _ string) bool { // want `golang.org/x/exp/maps.DeleteFunc\(\) can be replaced by maps.DeleteFunc\(\)` + return true + }) + + maps.Clear(m) // want `golang.org/x/exp/maps.Clear\(\) can be replaced by clear\(\)` + + fmt.Println("Hello") +} + +func _(a, b []string) { + slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` + slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + return true + }) + slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` + slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + return 0 + }) + slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` + slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + return true + }) + slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` + slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + return true + }) + slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` + slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` + slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + return true + }) + slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` + slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` + slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` + slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + return true + }) + slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` + slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` + slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` + slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` + slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + return 0 + }) + slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + return 0 + }) + slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` + slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + return 0 + }) + slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` + slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + return 0 + }) + slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` + slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + return 0 + }) + slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + return 0 + }) +} diff --git a/pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go b/pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go new file mode 100644 index 000000000000..16d117dd93c3 --- /dev/null +++ b/pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go @@ -0,0 +1,108 @@ +//go:build go1.23 + +//golangcitest:args -Eexptostd +package testdata + +/* + #include + #include + + void myprint(char* s) { + printf("%d\n", s); + } +*/ +import "C" + +import ( + "fmt" + "unsafe" + + "golang.org/x/exp/maps" + "golang.org/x/exp/slices" +) + +func _() { + cs := C.CString("Hello from stdio\n") + C.myprint(cs) + C.free(unsafe.Pointer(cs)) +} + +func _(m, a map[string]string) { + maps.Clone(m) // want `golang.org/x/exp/maps.Clone\(\) can be replaced by maps.Clone\(\)` + + maps.Keys(m) // want `golang.org/x/exp/maps.Keys\(\) can be replaced by slices.Collect\(maps.Keys\(\)\)` + + maps.Values(m) // want `golang.org/x/exp/maps.Values\(\) can be replaced by slices.Collect\(maps.Keys\(\)\)` + + maps.Equal(m, a) // want `golang.org/x/exp/maps.Equal\(\) can be replaced by maps.Equal\(\)` + + maps.EqualFunc(m, a, func(i, j string) bool { // want `golang.org/x/exp/maps.EqualFunc\(\) can be replaced by maps.EqualFunc\(\)` + return true + }) + + maps.Copy(m, a) // want `golang.org/x/exp/maps.Copy\(\) can be replaced by maps.Copy\(\)` + + maps.DeleteFunc(m, func(_, _ string) bool { // want `golang.org/x/exp/maps.DeleteFunc\(\) can be replaced by maps.DeleteFunc\(\)` + return true + }) + + maps.Clear(m) // want `golang.org/x/exp/maps.Clear\(\) can be replaced by clear\(\)` + + fmt.Println("Hello") +} + +func _(a, b []string) { + slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` + slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + return true + }) + slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` + slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + return 0 + }) + slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` + slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + return true + }) + slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` + slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + return true + }) + slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` + slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` + slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + return true + }) + slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` + slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` + slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` + slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + return true + }) + slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` + slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` + slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` + slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` + slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + return 0 + }) + slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + return 0 + }) + slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` + slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + return 0 + }) + slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` + slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + return 0 + }) + slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` + slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + return 0 + }) + slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + return 0 + }) +} diff --git a/pkg/golinters/exptostd/testdata/go.mod b/pkg/golinters/exptostd/testdata/go.mod new file mode 100644 index 000000000000..5261142a3036 --- /dev/null +++ b/pkg/golinters/exptostd/testdata/go.mod @@ -0,0 +1,5 @@ +module exptostd + +go 1.22.0 + +require golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 diff --git a/pkg/golinters/exptostd/testdata/go.sum b/pkg/golinters/exptostd/testdata/go.sum new file mode 100644 index 000000000000..c487fae960b3 --- /dev/null +++ b/pkg/golinters/exptostd/testdata/go.sum @@ -0,0 +1,2 @@ +golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo= +golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index 8f149117fb75..fe438248900a 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -26,6 +26,7 @@ import ( "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" "github.com/golangci/golangci-lint/pkg/golinters/forcetypeassert" @@ -283,6 +284,12 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithURL("https://github.com/kyoh86/exportloopref"). DeprecatedWarning("Since Go1.22 (loopvar) this linter is no longer relevant.", "v1.60.2", "copyloopvar"), + linter.NewConfig(exptostd.New()). + WithSince("v1.63.0"). + WithPresets(linter.PresetStyle). + WithLoadForGoAnalysis(). + WithURL("https://github.com/ldez/exptostd"), + linter.NewConfig(forbidigo.New(&cfg.LintersSettings.Forbidigo)). WithSince("v1.34.0"). WithPresets(linter.PresetStyle). From 8f400320532f7bd46653e29a4194edcf510fb48b Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 27 Dec 2024 17:21:56 +0100 Subject: [PATCH 2/5] feat: suggested fixes --- go.mod | 2 +- go.sum | 4 +- .../exptostd/exptostd_integration_test.go | 8 ++ .../exptostd/testdata/fix/in/exptostd.go | 113 ++++++++++++++++++ .../exptostd/testdata/fix/out/exptostd.go | 113 ++++++++++++++++++ 5 files changed, 237 insertions(+), 3 deletions(-) create mode 100644 pkg/golinters/exptostd/testdata/fix/in/exptostd.go create mode 100644 pkg/golinters/exptostd/testdata/fix/out/exptostd.go diff --git a/go.mod b/go.mod index 5efb93b6c2e0..18f0ed12797c 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,7 @@ require ( github.com/kunwardeep/paralleltest v1.0.10 github.com/kyoh86/exportloopref v0.1.11 github.com/lasiar/canonicalheader v1.1.2 - github.com/ldez/exptostd v0.1.0 + github.com/ldez/exptostd v0.2.0 github.com/ldez/gomoddirectives v0.6.0 github.com/ldez/grignotin v0.7.0 github.com/ldez/tagliatelle v0.7.1 diff --git a/go.sum b/go.sum index c3f84c238351..a2583f4acf8c 100644 --- a/go.sum +++ b/go.sum @@ -353,8 +353,8 @@ github.com/kyoh86/exportloopref v0.1.11 h1:1Z0bcmTypkL3Q4k+IDHMWTcnCliEZcaPiIe0/ github.com/kyoh86/exportloopref v0.1.11/go.mod h1:qkV4UF1zGl6EkF1ox8L5t9SwyeBAZ3qLMd6up458uqA= github.com/lasiar/canonicalheader v1.1.2 h1:vZ5uqwvDbyJCnMhmFYimgMZnJMjwljN5VGY0VKbMXb4= github.com/lasiar/canonicalheader v1.1.2/go.mod h1:qJCeLFS0G/QlLQ506T+Fk/fWMa2VmBUiEI2cuMK4djI= -github.com/ldez/exptostd v0.1.0 h1:/QkFfYxGpr8z1w7/BxBC49vm/kWLX5wi3TSxWC/DpVI= -github.com/ldez/exptostd v0.1.0/go.mod h1:iZBRYaUmcW5jwCR3KROEZ1KivQQp6PHXbDPk9hqJKCQ= +github.com/ldez/exptostd v0.2.0 h1:pyYXO5I5tyxcJqmg2q+UQtA/ckTRZy6J88lQ348KwqI= +github.com/ldez/exptostd v0.2.0/go.mod h1:iZBRYaUmcW5jwCR3KROEZ1KivQQp6PHXbDPk9hqJKCQ= github.com/ldez/gomoddirectives v0.6.0 h1:Jyf1ZdTeiIB4dd+2n4qw+g4aI9IJ6JyfOZ8BityWvnA= github.com/ldez/gomoddirectives v0.6.0/go.mod h1:TuwOGYoPAoENDWQpe8DMqEm5nIfjrxZXmxX/CExWyZ4= github.com/ldez/grignotin v0.7.0 h1:vh0dI32WhHaq6LLPZ38g7WxXuZ1+RzyrJ7iPG9JMa8c= diff --git a/pkg/golinters/exptostd/exptostd_integration_test.go b/pkg/golinters/exptostd/exptostd_integration_test.go index b9b291add7ff..8c8e325e2aa3 100644 --- a/pkg/golinters/exptostd/exptostd_integration_test.go +++ b/pkg/golinters/exptostd/exptostd_integration_test.go @@ -9,3 +9,11 @@ import ( func TestFromTestdata(t *testing.T) { integration.RunTestdata(t) } + +func TestFix(t *testing.T) { + integration.RunFix(t) +} + +func TestFixPathPrefix(t *testing.T) { + integration.RunFixPathPrefix(t) +} diff --git a/pkg/golinters/exptostd/testdata/fix/in/exptostd.go b/pkg/golinters/exptostd/testdata/fix/in/exptostd.go new file mode 100644 index 000000000000..3e1810ff9483 --- /dev/null +++ b/pkg/golinters/exptostd/testdata/fix/in/exptostd.go @@ -0,0 +1,113 @@ +//golangcitest:args -Eexptostd +package testdata + +import ( + "fmt" + + "golang.org/x/exp/maps" + "golang.org/x/exp/slices" +) + +func _(m, a map[string]string) { + maps.Clone(m) // want `golang.org/x/exp/maps.Clone\(\) can be replaced by maps.Clone\(\)` + + maps.Equal(m, a) // want `golang.org/x/exp/maps.Equal\(\) can be replaced by maps.Equal\(\)` + + maps.EqualFunc(m, a, func(i, j string) bool { // want `golang.org/x/exp/maps.EqualFunc\(\) can be replaced by maps.EqualFunc\(\)` + return true + }) + + maps.Copy(m, a) // want `golang.org/x/exp/maps.Copy\(\) can be replaced by maps.Copy\(\)` + + maps.DeleteFunc(m, func(_, _ string) bool { // want `golang.org/x/exp/maps.DeleteFunc\(\) can be replaced by maps.DeleteFunc\(\)` + return true + }) + + maps.Clear(m) // want `golang.org/x/exp/maps.Clear\(\) can be replaced by clear\(\)` + + fmt.Println("Hello") +} + +func _(a, b []string) { + slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` + + slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + return true + }) + + slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` + + slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + return 0 + }) + + slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` + + slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + return true + }) + + slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` + + slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + return true + }) + + slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` + + slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` + + slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + return true + }) + + slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` + + slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` + + slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` + + slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + return true + }) + + slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` + + slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` + + slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` + + slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` + + slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + return 0 + }) + + slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + return 0 + }) + + slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` + + slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + return 0 + }) + + slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` + + slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + return 0 + }) + + slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` + + slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + return 0 + }) + + slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` + + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + return 0 + }) +} diff --git a/pkg/golinters/exptostd/testdata/fix/out/exptostd.go b/pkg/golinters/exptostd/testdata/fix/out/exptostd.go new file mode 100644 index 000000000000..98052d7b89a3 --- /dev/null +++ b/pkg/golinters/exptostd/testdata/fix/out/exptostd.go @@ -0,0 +1,113 @@ +//golangcitest:args -Eexptostd +package testdata + +import ( + "fmt" + + "maps" + "slices" +) + +func _(m, a map[string]string) { + maps.Clone(m) // want `golang.org/x/exp/maps.Clone\(\) can be replaced by maps.Clone\(\)` + + maps.Equal(m, a) // want `golang.org/x/exp/maps.Equal\(\) can be replaced by maps.Equal\(\)` + + maps.EqualFunc(m, a, func(i, j string) bool { // want `golang.org/x/exp/maps.EqualFunc\(\) can be replaced by maps.EqualFunc\(\)` + return true + }) + + maps.Copy(m, a) // want `golang.org/x/exp/maps.Copy\(\) can be replaced by maps.Copy\(\)` + + maps.DeleteFunc(m, func(_, _ string) bool { // want `golang.org/x/exp/maps.DeleteFunc\(\) can be replaced by maps.DeleteFunc\(\)` + return true + }) + + clear(m) // want `golang.org/x/exp/maps.Clear\(\) can be replaced by clear\(\)` + + fmt.Println("Hello") +} + +func _(a, b []string) { + slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` + + slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + return true + }) + + slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` + + slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + return 0 + }) + + slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` + + slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + return true + }) + + slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` + + slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + return true + }) + + slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` + + slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` + + slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + return true + }) + + slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` + + slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` + + slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` + + slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + return true + }) + + slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` + + slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` + + slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` + + slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` + + slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + return 0 + }) + + slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + return 0 + }) + + slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` + + slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + return 0 + }) + + slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` + + slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + return 0 + }) + + slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` + + slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + return 0 + }) + + slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` + + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + return 0 + }) +} From 3d774dfb1fb029e6194fc7d75cbdda2387a39baf Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 27 Dec 2024 17:39:12 +0100 Subject: [PATCH 3/5] tests: update tests --- pkg/golinters/exptostd/testdata/exptostd.go | 4 ++-- pkg/golinters/exptostd/testdata/exptostd_cgo.go | 4 ++-- pkg/golinters/exptostd/testdata/exptostd_go123.go | 6 +++--- pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go | 6 +++--- pkg/golinters/exptostd/testdata/fix/in/exptostd.go | 4 ++-- pkg/golinters/exptostd/testdata/fix/out/exptostd.go | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/golinters/exptostd/testdata/exptostd.go b/pkg/golinters/exptostd/testdata/exptostd.go index 53f0d303bb65..af9ec7085ccb 100644 --- a/pkg/golinters/exptostd/testdata/exptostd.go +++ b/pkg/golinters/exptostd/testdata/exptostd.go @@ -4,8 +4,8 @@ package testdata import ( "fmt" - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" + "golang.org/x/exp/maps" // want `Import statement 'golang.org/x/exp/maps' can be replaced by 'maps'` + "golang.org/x/exp/slices" // want `Import statement 'golang.org/x/exp/slices' can be replaced by 'slices'` ) func _(m, a map[string]string) { diff --git a/pkg/golinters/exptostd/testdata/exptostd_cgo.go b/pkg/golinters/exptostd/testdata/exptostd_cgo.go index cdb7aa4fbf68..c6a96d035268 100644 --- a/pkg/golinters/exptostd/testdata/exptostd_cgo.go +++ b/pkg/golinters/exptostd/testdata/exptostd_cgo.go @@ -15,8 +15,8 @@ import ( "fmt" "unsafe" - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" + "golang.org/x/exp/maps" // want `Import statement 'golang.org/x/exp/maps' can be replaced by 'maps'` + "golang.org/x/exp/slices" // want `Import statement 'golang.org/x/exp/slices' can be replaced by 'slices'` ) func _() { diff --git a/pkg/golinters/exptostd/testdata/exptostd_go123.go b/pkg/golinters/exptostd/testdata/exptostd_go123.go index 4a997eca5961..4f195d22bdf7 100644 --- a/pkg/golinters/exptostd/testdata/exptostd_go123.go +++ b/pkg/golinters/exptostd/testdata/exptostd_go123.go @@ -6,8 +6,8 @@ package testdata import ( "fmt" - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" + "golang.org/x/exp/maps" // want `Import statement 'golang.org/x/exp/maps' can be replaced by 'maps'` + "golang.org/x/exp/slices" // want `Import statement 'golang.org/x/exp/slices' can be replaced by 'slices'` ) func _(m, a map[string]string) { @@ -15,7 +15,7 @@ func _(m, a map[string]string) { maps.Keys(m) // want `golang.org/x/exp/maps.Keys\(\) can be replaced by slices.Collect\(maps.Keys\(\)\)` - maps.Values(m) // want `golang.org/x/exp/maps.Values\(\) can be replaced by slices.Collect\(maps.Keys\(\)\)` + maps.Values(m) // want `golang.org/x/exp/maps.Values\(\) can be replaced by slices.Collect\(maps.Values\(\)\)` maps.Equal(m, a) // want `golang.org/x/exp/maps.Equal\(\) can be replaced by maps.Equal\(\)` diff --git a/pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go b/pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go index 16d117dd93c3..2deacf0536dc 100644 --- a/pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go +++ b/pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go @@ -17,8 +17,8 @@ import ( "fmt" "unsafe" - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" + "golang.org/x/exp/maps" // want `Import statement 'golang.org/x/exp/maps' can be replaced by 'maps'` + "golang.org/x/exp/slices" // want `Import statement 'golang.org/x/exp/slices' can be replaced by 'slices'` ) func _() { @@ -32,7 +32,7 @@ func _(m, a map[string]string) { maps.Keys(m) // want `golang.org/x/exp/maps.Keys\(\) can be replaced by slices.Collect\(maps.Keys\(\)\)` - maps.Values(m) // want `golang.org/x/exp/maps.Values\(\) can be replaced by slices.Collect\(maps.Keys\(\)\)` + maps.Values(m) // want `golang.org/x/exp/maps.Values\(\) can be replaced by slices.Collect\(maps.Values\(\)\)` maps.Equal(m, a) // want `golang.org/x/exp/maps.Equal\(\) can be replaced by maps.Equal\(\)` diff --git a/pkg/golinters/exptostd/testdata/fix/in/exptostd.go b/pkg/golinters/exptostd/testdata/fix/in/exptostd.go index 3e1810ff9483..243fe1ab7d47 100644 --- a/pkg/golinters/exptostd/testdata/fix/in/exptostd.go +++ b/pkg/golinters/exptostd/testdata/fix/in/exptostd.go @@ -4,8 +4,8 @@ package testdata import ( "fmt" - "golang.org/x/exp/maps" - "golang.org/x/exp/slices" + "golang.org/x/exp/maps" // want `Import statement 'golang.org/x/exp/maps' can be replaced by 'maps'` + "golang.org/x/exp/slices" // want `Import statement 'golang.org/x/exp/slices' can be replaced by 'slices'` ) func _(m, a map[string]string) { diff --git a/pkg/golinters/exptostd/testdata/fix/out/exptostd.go b/pkg/golinters/exptostd/testdata/fix/out/exptostd.go index 98052d7b89a3..2da7b189188b 100644 --- a/pkg/golinters/exptostd/testdata/fix/out/exptostd.go +++ b/pkg/golinters/exptostd/testdata/fix/out/exptostd.go @@ -4,8 +4,8 @@ package testdata import ( "fmt" - "maps" - "slices" + "maps" // want `Import statement 'golang.org/x/exp/maps' can be replaced by 'maps'` + "slices" // want `Import statement 'golang.org/x/exp/slices' can be replaced by 'slices'` ) func _(m, a map[string]string) { From d56c50d924d08be371300b53a569c50caf42b856 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 27 Dec 2024 17:41:53 +0100 Subject: [PATCH 4/5] feat: flag as autofixable --- pkg/lint/lintersdb/builder_linter.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index fe438248900a..4338aa88ccf9 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -288,6 +288,7 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithSince("v1.63.0"). WithPresets(linter.PresetStyle). WithLoadForGoAnalysis(). + WithAutoFix(). WithURL("https://github.com/ldez/exptostd"), linter.NewConfig(forbidigo.New(&cfg.LintersSettings.Forbidigo)). From ed82a695e8932e87ff5632a5d7662f776c243fda Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Mon, 30 Dec 2024 17:22:33 +0100 Subject: [PATCH 5/5] feat: improves slices reports --- go.mod | 2 +- go.sum | 4 +- pkg/golinters/exptostd/testdata/exptostd.go | 58 +++++++++---------- .../exptostd/testdata/exptostd_cgo.go | 58 +++++++++---------- .../exptostd/testdata/exptostd_go123.go | 58 +++++++++---------- .../exptostd/testdata/exptostd_go123_cgo.go | 58 +++++++++---------- .../exptostd/testdata/fix/in/exptostd.go | 58 +++++++++---------- .../exptostd/testdata/fix/out/exptostd.go | 58 +++++++++---------- 8 files changed, 177 insertions(+), 177 deletions(-) diff --git a/go.mod b/go.mod index 18f0ed12797c..7bbf802cc9f1 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,7 @@ require ( github.com/kunwardeep/paralleltest v1.0.10 github.com/kyoh86/exportloopref v0.1.11 github.com/lasiar/canonicalheader v1.1.2 - github.com/ldez/exptostd v0.2.0 + github.com/ldez/exptostd v0.3.0 github.com/ldez/gomoddirectives v0.6.0 github.com/ldez/grignotin v0.7.0 github.com/ldez/tagliatelle v0.7.1 diff --git a/go.sum b/go.sum index a2583f4acf8c..a3d4b0fb7ee1 100644 --- a/go.sum +++ b/go.sum @@ -353,8 +353,8 @@ github.com/kyoh86/exportloopref v0.1.11 h1:1Z0bcmTypkL3Q4k+IDHMWTcnCliEZcaPiIe0/ github.com/kyoh86/exportloopref v0.1.11/go.mod h1:qkV4UF1zGl6EkF1ox8L5t9SwyeBAZ3qLMd6up458uqA= github.com/lasiar/canonicalheader v1.1.2 h1:vZ5uqwvDbyJCnMhmFYimgMZnJMjwljN5VGY0VKbMXb4= github.com/lasiar/canonicalheader v1.1.2/go.mod h1:qJCeLFS0G/QlLQ506T+Fk/fWMa2VmBUiEI2cuMK4djI= -github.com/ldez/exptostd v0.2.0 h1:pyYXO5I5tyxcJqmg2q+UQtA/ckTRZy6J88lQ348KwqI= -github.com/ldez/exptostd v0.2.0/go.mod h1:iZBRYaUmcW5jwCR3KROEZ1KivQQp6PHXbDPk9hqJKCQ= +github.com/ldez/exptostd v0.3.0 h1:iKdMtUedzov89jDvuwmo0qpo+ARpZJg9hMp3428WwNg= +github.com/ldez/exptostd v0.3.0/go.mod h1:iZBRYaUmcW5jwCR3KROEZ1KivQQp6PHXbDPk9hqJKCQ= github.com/ldez/gomoddirectives v0.6.0 h1:Jyf1ZdTeiIB4dd+2n4qw+g4aI9IJ6JyfOZ8BityWvnA= github.com/ldez/gomoddirectives v0.6.0/go.mod h1:TuwOGYoPAoENDWQpe8DMqEm5nIfjrxZXmxX/CExWyZ4= github.com/ldez/grignotin v0.7.0 h1:vh0dI32WhHaq6LLPZ38g7WxXuZ1+RzyrJ7iPG9JMa8c= diff --git a/pkg/golinters/exptostd/testdata/exptostd.go b/pkg/golinters/exptostd/testdata/exptostd.go index af9ec7085ccb..527da55211c0 100644 --- a/pkg/golinters/exptostd/testdata/exptostd.go +++ b/pkg/golinters/exptostd/testdata/exptostd.go @@ -29,57 +29,57 @@ func _(m, a map[string]string) { } func _(a, b []string) { - slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` - slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + slices.Equal(a, b) + slices.EqualFunc(a, b, func(_ string, _ string) bool { return true }) - slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` - slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + slices.Compare(a, b) + slices.CompareFunc(a, b, func(_ string, _ string) int { return 0 }) - slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` - slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + slices.Index(a, "a") + slices.IndexFunc(a, func(_ string) bool { return true }) - slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` - slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + slices.Contains(a, "a") + slices.ContainsFunc(a, func(_ string) bool { return true }) - slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` - slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` - slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + slices.Insert(a, 0, "a", "b") + slices.Delete(a, 0, 1) + slices.DeleteFunc(a, func(_ string) bool { return true }) - slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` - slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` - slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` - slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + slices.Replace(a, 0, 1, "a") + slices.Clone(a) + slices.Compact(a) + slices.CompactFunc(a, func(_ string, _ string) bool { return true }) - slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` - slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` - slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` - slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` - slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + slices.Grow(a, 2) + slices.Clip(a) + slices.Reverse(a) + slices.Sort(a) + slices.SortFunc(a, func(_, _ string) int { return 0 }) - slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + slices.SortStableFunc(a, func(_, _ string) int { return 0 }) - slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` - slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + slices.IsSorted(a) + slices.IsSortedFunc(a, func(_, _ string) int { return 0 }) - slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` - slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + slices.Min(a) + slices.MinFunc(a, func(_, _ string) int { return 0 }) - slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` - slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + slices.Max(a) + slices.MaxFunc(a, func(_, _ string) int { return 0 }) - slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` - slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + slices.BinarySearch(a, "a") + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { return 0 }) } diff --git a/pkg/golinters/exptostd/testdata/exptostd_cgo.go b/pkg/golinters/exptostd/testdata/exptostd_cgo.go index c6a96d035268..f036865f2ba4 100644 --- a/pkg/golinters/exptostd/testdata/exptostd_cgo.go +++ b/pkg/golinters/exptostd/testdata/exptostd_cgo.go @@ -46,57 +46,57 @@ func _(m, a map[string]string) { } func _(a, b []string) { - slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` - slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + slices.Equal(a, b) + slices.EqualFunc(a, b, func(_ string, _ string) bool { return true }) - slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` - slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + slices.Compare(a, b) + slices.CompareFunc(a, b, func(_ string, _ string) int { return 0 }) - slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` - slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + slices.Index(a, "a") + slices.IndexFunc(a, func(_ string) bool { return true }) - slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` - slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + slices.Contains(a, "a") + slices.ContainsFunc(a, func(_ string) bool { return true }) - slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` - slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` - slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + slices.Insert(a, 0, "a", "b") + slices.Delete(a, 0, 1) + slices.DeleteFunc(a, func(_ string) bool { return true }) - slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` - slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` - slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` - slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + slices.Replace(a, 0, 1, "a") + slices.Clone(a) + slices.Compact(a) + slices.CompactFunc(a, func(_ string, _ string) bool { return true }) - slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` - slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` - slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` - slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` - slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + slices.Grow(a, 2) + slices.Clip(a) + slices.Reverse(a) + slices.Sort(a) + slices.SortFunc(a, func(_, _ string) int { return 0 }) - slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + slices.SortStableFunc(a, func(_, _ string) int { return 0 }) - slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` - slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + slices.IsSorted(a) + slices.IsSortedFunc(a, func(_, _ string) int { return 0 }) - slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` - slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + slices.Min(a) + slices.MinFunc(a, func(_, _ string) int { return 0 }) - slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` - slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + slices.Max(a) + slices.MaxFunc(a, func(_, _ string) int { return 0 }) - slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` - slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + slices.BinarySearch(a, "a") + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { return 0 }) } diff --git a/pkg/golinters/exptostd/testdata/exptostd_go123.go b/pkg/golinters/exptostd/testdata/exptostd_go123.go index 4f195d22bdf7..b610b2d727f5 100644 --- a/pkg/golinters/exptostd/testdata/exptostd_go123.go +++ b/pkg/golinters/exptostd/testdata/exptostd_go123.go @@ -35,57 +35,57 @@ func _(m, a map[string]string) { } func _(a, b []string) { - slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` - slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + slices.Equal(a, b) + slices.EqualFunc(a, b, func(_ string, _ string) bool { return true }) - slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` - slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + slices.Compare(a, b) + slices.CompareFunc(a, b, func(_ string, _ string) int { return 0 }) - slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` - slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + slices.Index(a, "a") + slices.IndexFunc(a, func(_ string) bool { return true }) - slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` - slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + slices.Contains(a, "a") + slices.ContainsFunc(a, func(_ string) bool { return true }) - slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` - slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` - slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + slices.Insert(a, 0, "a", "b") + slices.Delete(a, 0, 1) + slices.DeleteFunc(a, func(_ string) bool { return true }) - slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` - slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` - slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` - slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + slices.Replace(a, 0, 1, "a") + slices.Clone(a) + slices.Compact(a) + slices.CompactFunc(a, func(_ string, _ string) bool { return true }) - slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` - slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` - slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` - slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` - slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + slices.Grow(a, 2) + slices.Clip(a) + slices.Reverse(a) + slices.Sort(a) + slices.SortFunc(a, func(_, _ string) int { return 0 }) - slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + slices.SortStableFunc(a, func(_, _ string) int { return 0 }) - slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` - slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + slices.IsSorted(a) + slices.IsSortedFunc(a, func(_, _ string) int { return 0 }) - slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` - slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + slices.Min(a) + slices.MinFunc(a, func(_, _ string) int { return 0 }) - slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` - slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + slices.Max(a) + slices.MaxFunc(a, func(_, _ string) int { return 0 }) - slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` - slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + slices.BinarySearch(a, "a") + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { return 0 }) } diff --git a/pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go b/pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go index 2deacf0536dc..892624fd38b0 100644 --- a/pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go +++ b/pkg/golinters/exptostd/testdata/exptostd_go123_cgo.go @@ -52,57 +52,57 @@ func _(m, a map[string]string) { } func _(a, b []string) { - slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` - slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + slices.Equal(a, b) + slices.EqualFunc(a, b, func(_ string, _ string) bool { return true }) - slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` - slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + slices.Compare(a, b) + slices.CompareFunc(a, b, func(_ string, _ string) int { return 0 }) - slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` - slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + slices.Index(a, "a") + slices.IndexFunc(a, func(_ string) bool { return true }) - slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` - slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + slices.Contains(a, "a") + slices.ContainsFunc(a, func(_ string) bool { return true }) - slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` - slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` - slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + slices.Insert(a, 0, "a", "b") + slices.Delete(a, 0, 1) + slices.DeleteFunc(a, func(_ string) bool { return true }) - slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` - slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` - slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` - slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + slices.Replace(a, 0, 1, "a") + slices.Clone(a) + slices.Compact(a) + slices.CompactFunc(a, func(_ string, _ string) bool { return true }) - slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` - slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` - slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` - slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` - slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + slices.Grow(a, 2) + slices.Clip(a) + slices.Reverse(a) + slices.Sort(a) + slices.SortFunc(a, func(_, _ string) int { return 0 }) - slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + slices.SortStableFunc(a, func(_, _ string) int { return 0 }) - slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` - slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + slices.IsSorted(a) + slices.IsSortedFunc(a, func(_, _ string) int { return 0 }) - slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` - slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + slices.Min(a) + slices.MinFunc(a, func(_, _ string) int { return 0 }) - slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` - slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + slices.Max(a) + slices.MaxFunc(a, func(_, _ string) int { return 0 }) - slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` - slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + slices.BinarySearch(a, "a") + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { return 0 }) } diff --git a/pkg/golinters/exptostd/testdata/fix/in/exptostd.go b/pkg/golinters/exptostd/testdata/fix/in/exptostd.go index 243fe1ab7d47..d9642737dd58 100644 --- a/pkg/golinters/exptostd/testdata/fix/in/exptostd.go +++ b/pkg/golinters/exptostd/testdata/fix/in/exptostd.go @@ -29,85 +29,85 @@ func _(m, a map[string]string) { } func _(a, b []string) { - slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` + slices.Equal(a, b) - slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + slices.EqualFunc(a, b, func(_ string, _ string) bool { return true }) - slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` + slices.Compare(a, b) - slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + slices.CompareFunc(a, b, func(_ string, _ string) int { return 0 }) - slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` + slices.Index(a, "a") - slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + slices.IndexFunc(a, func(_ string) bool { return true }) - slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` + slices.Contains(a, "a") - slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + slices.ContainsFunc(a, func(_ string) bool { return true }) - slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` + slices.Insert(a, 0, "a", "b") - slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` + slices.Delete(a, 0, 1) - slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + slices.DeleteFunc(a, func(_ string) bool { return true }) - slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` + slices.Replace(a, 0, 1, "a") - slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` + slices.Clone(a) - slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` + slices.Compact(a) - slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + slices.CompactFunc(a, func(_ string, _ string) bool { return true }) - slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` + slices.Grow(a, 2) - slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` + slices.Clip(a) - slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` + slices.Reverse(a) - slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` + slices.Sort(a) - slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + slices.SortFunc(a, func(_, _ string) int { return 0 }) - slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + slices.SortStableFunc(a, func(_, _ string) int { return 0 }) - slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` + slices.IsSorted(a) - slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + slices.IsSortedFunc(a, func(_, _ string) int { return 0 }) - slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` + slices.Min(a) - slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + slices.MinFunc(a, func(_, _ string) int { return 0 }) - slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` + slices.Max(a) - slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + slices.MaxFunc(a, func(_, _ string) int { return 0 }) - slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` + slices.BinarySearch(a, "a") - slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { return 0 }) } diff --git a/pkg/golinters/exptostd/testdata/fix/out/exptostd.go b/pkg/golinters/exptostd/testdata/fix/out/exptostd.go index 2da7b189188b..5ebf6d5900f8 100644 --- a/pkg/golinters/exptostd/testdata/fix/out/exptostd.go +++ b/pkg/golinters/exptostd/testdata/fix/out/exptostd.go @@ -29,85 +29,85 @@ func _(m, a map[string]string) { } func _(a, b []string) { - slices.Equal(a, b) // want `golang.org/x/exp/slices\.Equal\(\) can be replaced by slices\.Equal\(\)` + slices.Equal(a, b) - slices.EqualFunc(a, b, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.EqualFunc\(\) can be replaced by slices\.EqualFunc\(\)` + slices.EqualFunc(a, b, func(_ string, _ string) bool { return true }) - slices.Compare(a, b) // want `golang.org/x/exp/slices\.Compare\(\) can be replaced by slices\.Compare\(\)` + slices.Compare(a, b) - slices.CompareFunc(a, b, func(_ string, _ string) int { // want `golang.org/x/exp/slices\.CompareFunc\(\) can be replaced by slices\.CompareFunc\(\)` + slices.CompareFunc(a, b, func(_ string, _ string) int { return 0 }) - slices.Index(a, "a") // want `golang.org/x/exp/slices\.Index\(\) can be replaced by slices\.Index\(\)` + slices.Index(a, "a") - slices.IndexFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.IndexFunc\(\) can be replaced by slices\.IndexFunc\(\)` + slices.IndexFunc(a, func(_ string) bool { return true }) - slices.Contains(a, "a") // want `golang.org/x/exp/slices\.Contains\(\) can be replaced by slices\.Contains\(\)` + slices.Contains(a, "a") - slices.ContainsFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.ContainsFunc\(\) can be replaced by slices\.ContainsFunc\(\)` + slices.ContainsFunc(a, func(_ string) bool { return true }) - slices.Insert(a, 0, "a", "b") // want `golang.org/x/exp/slices\.Insert\(\) can be replaced by slices\.Insert\(\)` + slices.Insert(a, 0, "a", "b") - slices.Delete(a, 0, 1) // want `golang.org/x/exp/slices\.Delete\(\) can be replaced by slices\.Delete\(\)` + slices.Delete(a, 0, 1) - slices.DeleteFunc(a, func(_ string) bool { // want `golang.org/x/exp/slices\.DeleteFunc\(\) can be replaced by slices\.DeleteFunc\(\)` + slices.DeleteFunc(a, func(_ string) bool { return true }) - slices.Replace(a, 0, 1, "a") // want `golang.org/x/exp/slices\.Replace\(\) can be replaced by slices\.Replace\(\)` + slices.Replace(a, 0, 1, "a") - slices.Clone(a) // want `golang.org/x/exp/slices\.Clone\(\) can be replaced by slices\.Clone\(\)` + slices.Clone(a) - slices.Compact(a) // want `golang.org/x/exp/slices\.Compact\(\) can be replaced by slices\.Compact\(\)` + slices.Compact(a) - slices.CompactFunc(a, func(_ string, _ string) bool { // want `golang.org/x/exp/slices\.CompactFunc\(\) can be replaced by slices\.CompactFunc\(\)` + slices.CompactFunc(a, func(_ string, _ string) bool { return true }) - slices.Grow(a, 2) // want `golang.org/x/exp/slices\.Grow\(\) can be replaced by slices\.Grow\(\)` + slices.Grow(a, 2) - slices.Clip(a) // want `golang.org/x/exp/slices\.Clip\(\) can be replaced by slices\.Clip\(\)` + slices.Clip(a) - slices.Reverse(a) // want `golang.org/x/exp/slices\.Reverse\(\) can be replaced by slices\.Reverse\(\)` + slices.Reverse(a) - slices.Sort(a) // want `golang.org/x/exp/slices\.Sort\(\) can be replaced by slices\.Sort\(\)` + slices.Sort(a) - slices.SortFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortFunc\(\) can be replaced by slices\.SortFunc\(\)` + slices.SortFunc(a, func(_, _ string) int { return 0 }) - slices.SortStableFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.SortStableFunc\(\) can be replaced by slices\.SortStableFunc\(\)` + slices.SortStableFunc(a, func(_, _ string) int { return 0 }) - slices.IsSorted(a) // want `golang.org/x/exp/slices\.IsSorted\(\) can be replaced by slices\.IsSorted\(\)` + slices.IsSorted(a) - slices.IsSortedFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.IsSortedFunc\(\) can be replaced by slices\.IsSortedFunc\(\)` + slices.IsSortedFunc(a, func(_, _ string) int { return 0 }) - slices.Min(a) // want `golang.org/x/exp/slices\.Min\(\) can be replaced by slices\.Min\(\)` + slices.Min(a) - slices.MinFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MinFunc\(\) can be replaced by slices\.MinFunc\(\)` + slices.MinFunc(a, func(_, _ string) int { return 0 }) - slices.Max(a) // want `golang.org/x/exp/slices\.Max\(\) can be replaced by slices\.Max\(\)` + slices.Max(a) - slices.MaxFunc(a, func(_, _ string) int { // want `golang.org/x/exp/slices\.MaxFunc\(\) can be replaced by slices\.MaxFunc\(\)` + slices.MaxFunc(a, func(_, _ string) int { return 0 }) - slices.BinarySearch(a, "a") // want `golang.org/x/exp/slices\.BinarySearch\(\) can be replaced by slices\.BinarySearch\(\)` + slices.BinarySearch(a, "a") - slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { // want `golang.org/x/exp/slices\.BinarySearchFunc\(\) can be replaced by slices\.BinarySearchFunc\(\)` + slices.BinarySearchFunc(a, b, func(_ string, _ []string) int { return 0 }) }