From 61fd1d25ddf4b8393129a115e978fb1fe2996559 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Sat, 7 Jan 2023 00:30:58 -0800 Subject: [PATCH 1/9] Add gocheckdirectives --- .golangci.reference.yml | 2 ++ .golangci.yml | 1 + go.mod | 1 + go.sum | 2 ++ pkg/golinters/gocheckdirectives.go | 24 ++++++++++++++++++++++++ test/testdata/gocheckdirectives.go | 19 +++++++++++++++++++ 6 files changed, 49 insertions(+) create mode 100644 pkg/golinters/gocheckdirectives.go create mode 100644 test/testdata/gocheckdirectives.go diff --git a/.golangci.reference.yml b/.golangci.reference.yml index bc30cd626754..6a6a57165b20 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -2014,6 +2014,7 @@ linters: - funlen - gci - ginkgolinter + - gocheckdirectives - gochecknoglobals - gochecknoinits - gocognit @@ -2123,6 +2124,7 @@ linters: - funlen - gci - ginkgolinter + - gocheckdirectives - gochecknoglobals - gochecknoinits - gocognit diff --git a/.golangci.yml b/.golangci.yml index 3e0c4511ec86..6c81b20d52b6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -74,6 +74,7 @@ linters: - errcheck - exportloopref - funlen + - gocheckdirectives - gochecknoinits - goconst - gocritic diff --git a/go.mod b/go.mod index 4848f9bc9ae8..095c15336acc 100644 --- a/go.mod +++ b/go.mod @@ -59,6 +59,7 @@ require ( github.com/kyoh86/exportloopref v0.1.11 github.com/ldez/gomoddirectives v0.2.3 github.com/ldez/tagliatelle v0.4.0 + github.com/leighmcculloch/gocheckdirectives v1.0.1 github.com/leonklingele/grouper v1.1.1 github.com/lufeee/execinquery v1.2.1 github.com/maratori/testableexamples v1.0.0 diff --git a/go.sum b/go.sum index 76332121c446..763f4db5201d 100644 --- a/go.sum +++ b/go.sum @@ -338,6 +338,8 @@ github.com/ldez/gomoddirectives v0.2.3 h1:y7MBaisZVDYmKvt9/l1mjNCiSA1BVn34U0ObUc github.com/ldez/gomoddirectives v0.2.3/go.mod h1:cpgBogWITnCfRq2qGoDkKMEVSaarhdBr6g8G04uz6d0= github.com/ldez/tagliatelle v0.4.0 h1:sylp7d9kh6AdXN2DpVGHBRb5guTVAgOxqNGhbqc4b1c= github.com/ldez/tagliatelle v0.4.0/go.mod h1:mNtTfrHy2haaBAw+VT7IBV6VXBThS7TCreYWbBcJ87I= +github.com/leighmcculloch/gocheckdirectives v1.0.1 h1:Undd42T6tnVsIiWuAwoKPEG6QF/xKy9Ucl+qI0T0/cQ= +github.com/leighmcculloch/gocheckdirectives v1.0.1/go.mod h1:qzvgLLfQOtycOXpnc8woQW5r6kHyl5xzXq4K/zDRS2E= github.com/leonklingele/grouper v1.1.1 h1:suWXRU57D4/Enn6pXR0QVqqWWrnJ9Osrz+5rjt8ivzU= github.com/leonklingele/grouper v1.1.1/go.mod h1:uk3I3uDfi9B6PeUjsCKi6ndcf63Uy7snXgR4yDYQVDY= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= diff --git a/pkg/golinters/gocheckdirectives.go b/pkg/golinters/gocheckdirectives.go new file mode 100644 index 000000000000..cac57721acbc --- /dev/null +++ b/pkg/golinters/gocheckdirectives.go @@ -0,0 +1,24 @@ +package golinters + +import ( + "github.com/leighmcculloch/gocheckdirectives/checkdirectives" + "golang.org/x/tools/go/analysis" + + "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" +) + +func NewGocheckdirectives() *goanalysis.Linter { + gocheckdirectives := checkdirectives.Analyzer() + + // gocheckdirectives has no config. + linterConfig := map[string]map[string]interface{}{ + gocheckdirectives.Name: {}, + } + + return goanalysis.NewLinter( + gocheckdirectives.Name, + gocheckdirectives.Doc, + []*analysis.Analyzer{gocheckdirectives}, + linterConfig, + ).WithLoadMode(goanalysis.LoadModeSyntax) +} diff --git a/test/testdata/gocheckdirectives.go b/test/testdata/gocheckdirectives.go new file mode 100644 index 000000000000..ba9a08f1acd9 --- /dev/null +++ b/test/testdata/gocheckdirectives.go @@ -0,0 +1,19 @@ +//golangcitest:args -Egocheckdirectives +package testdata + +// Okay cases: + +//go:generate echo hello world + +//go:embed +var Value string + +//go: + +// Problematic cases: + +// go:embed // want "go directive contains leading space: // go:embed" + +// go:embed // want "go directive contains leading space: // go:embed" + +//go:genrate // want "unrecognized go directive: //go:genrate" From 2948d5b5d834a487fd22206a4e68e5866b0f1820 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Sat, 7 Jan 2023 09:42:53 -0800 Subject: [PATCH 2/9] Add stdlib import to test --- test/testdata/gocheckdirectives.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/testdata/gocheckdirectives.go b/test/testdata/gocheckdirectives.go index ba9a08f1acd9..558627d6c23e 100644 --- a/test/testdata/gocheckdirectives.go +++ b/test/testdata/gocheckdirectives.go @@ -1,5 +1,7 @@ //golangcitest:args -Egocheckdirectives -package testdata +package testdat + +import _ "embed" // Okay cases: From 2b72f0685327e8545f1e86e0e208c73b437993fc Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Sat, 7 Jan 2023 09:45:34 -0800 Subject: [PATCH 3/9] Remove enabling gocheckdirectives from .golangci.yml --- .golangci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 6c81b20d52b6..3e0c4511ec86 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -74,7 +74,6 @@ linters: - errcheck - exportloopref - funlen - - gocheckdirectives - gochecknoinits - goconst - gocritic From 0f3453f450ed0a28955323cd2c889e2d0e514ea7 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:22:05 -0800 Subject: [PATCH 4/9] Add missing manager hook up --- pkg/lint/lintersdb/manager.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 6ea531b8f817..e96d36d8b189 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -440,6 +440,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/nunnatsa/ginkgolinter"), + linter.NewConfig(golinters.NewGocheckdirectives()). + WithSince("v1.51.0"). + WithPresets(linter.PresetBugs). + WithURL("https://github.com/leighmcculloch/gocheckdirectives"), + linter.NewConfig(golinters.NewGochecknoglobals()). WithSince("v1.12.0"). WithPresets(linter.PresetStyle). From f9e11076843d288ed241bb4020e057cd5283c75d Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:56:45 -0800 Subject: [PATCH 5/9] Fix package name --- test/testdata/gocheckdirectives.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testdata/gocheckdirectives.go b/test/testdata/gocheckdirectives.go index 558627d6c23e..6d95d187c314 100644 --- a/test/testdata/gocheckdirectives.go +++ b/test/testdata/gocheckdirectives.go @@ -1,5 +1,5 @@ //golangcitest:args -Egocheckdirectives -package testdat +package testdata import _ "embed" From 0cb13d124794d1adb10530269e6a7dbe234f8d70 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 13 Jan 2023 23:51:15 -0800 Subject: [PATCH 6/9] Rename to gocheckcompilerdirectives --- .golangci.reference.yml | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- pkg/golinters/gocheckdirectives.go | 16 ++++++++-------- pkg/lint/lintersdb/manager.go | 4 ++-- test/testdata/gocheckdirectives.go | 8 ++++---- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.golangci.reference.yml b/.golangci.reference.yml index 6a6a57165b20..efd9b770d91d 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -2014,7 +2014,7 @@ linters: - funlen - gci - ginkgolinter - - gocheckdirectives + - gocheckcompilerdirectives - gochecknoglobals - gochecknoinits - gocognit @@ -2124,7 +2124,7 @@ linters: - funlen - gci - ginkgolinter - - gocheckdirectives + - gocheckcompilerdirectives - gochecknoglobals - gochecknoinits - gocognit diff --git a/go.mod b/go.mod index 095c15336acc..aa3050ed8e33 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/golangci/golangci-lint go 1.19 require ( + 4d63.com/gocheckcompilerdirectives v1.1.0 4d63.com/gochecknoglobals v0.1.0 github.com/Abirdcfly/dupword v0.0.9 github.com/Antonboom/errname v0.1.7 @@ -59,7 +60,6 @@ require ( github.com/kyoh86/exportloopref v0.1.11 github.com/ldez/gomoddirectives v0.2.3 github.com/ldez/tagliatelle v0.4.0 - github.com/leighmcculloch/gocheckdirectives v1.0.1 github.com/leonklingele/grouper v1.1.1 github.com/lufeee/execinquery v1.2.1 github.com/maratori/testableexamples v1.0.0 diff --git a/go.sum b/go.sum index 763f4db5201d..85628a875d3a 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +4d63.com/gocheckcompilerdirectives v1.1.0 h1:K+4Mp919vYeovlulJrd5dAiHL++f69Hjbu+P5BIv8yg= +4d63.com/gocheckcompilerdirectives v1.1.0/go.mod h1:yjDJSxmDTtIHHCqX0ufRYZDL6vQtMG7tJdKVeWwsqvs= 4d63.com/gochecknoglobals v0.1.0 h1:zeZSRqj5yCg28tCkIV/z/lWbwvNm5qnKVS15PI8nhD0= 4d63.com/gochecknoglobals v0.1.0/go.mod h1:wfdC5ZjKSPr7CybKEcgJhUOgeAQW1+7WcyK8OvUilfo= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= @@ -338,8 +340,6 @@ github.com/ldez/gomoddirectives v0.2.3 h1:y7MBaisZVDYmKvt9/l1mjNCiSA1BVn34U0ObUc github.com/ldez/gomoddirectives v0.2.3/go.mod h1:cpgBogWITnCfRq2qGoDkKMEVSaarhdBr6g8G04uz6d0= github.com/ldez/tagliatelle v0.4.0 h1:sylp7d9kh6AdXN2DpVGHBRb5guTVAgOxqNGhbqc4b1c= github.com/ldez/tagliatelle v0.4.0/go.mod h1:mNtTfrHy2haaBAw+VT7IBV6VXBThS7TCreYWbBcJ87I= -github.com/leighmcculloch/gocheckdirectives v1.0.1 h1:Undd42T6tnVsIiWuAwoKPEG6QF/xKy9Ucl+qI0T0/cQ= -github.com/leighmcculloch/gocheckdirectives v1.0.1/go.mod h1:qzvgLLfQOtycOXpnc8woQW5r6kHyl5xzXq4K/zDRS2E= github.com/leonklingele/grouper v1.1.1 h1:suWXRU57D4/Enn6pXR0QVqqWWrnJ9Osrz+5rjt8ivzU= github.com/leonklingele/grouper v1.1.1/go.mod h1:uk3I3uDfi9B6PeUjsCKi6ndcf63Uy7snXgR4yDYQVDY= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= diff --git a/pkg/golinters/gocheckdirectives.go b/pkg/golinters/gocheckdirectives.go index cac57721acbc..03fff7078121 100644 --- a/pkg/golinters/gocheckdirectives.go +++ b/pkg/golinters/gocheckdirectives.go @@ -1,24 +1,24 @@ package golinters import ( - "github.com/leighmcculloch/gocheckdirectives/checkdirectives" + "4d63.com/gocheckcompilerdirectives/checkcompilerdirectives" "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" ) -func NewGocheckdirectives() *goanalysis.Linter { - gocheckdirectives := checkdirectives.Analyzer() +func NewGocheckcompilerdirectives() *goanalysis.Linter { + gocheckcompilerdirectives := checkcompilerdirectives.Analyzer() - // gocheckdirectives has no config. + // gocheckcompilerdirectives has no config. linterConfig := map[string]map[string]interface{}{ - gocheckdirectives.Name: {}, + gocheckcompilerdirectives.Name: {}, } return goanalysis.NewLinter( - gocheckdirectives.Name, - gocheckdirectives.Doc, - []*analysis.Analyzer{gocheckdirectives}, + gocheckcompilerdirectives.Name, + gocheckcompilerdirectives.Doc, + []*analysis.Analyzer{gocheckcompilerdirectives}, linterConfig, ).WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index e96d36d8b189..2f691c4124bb 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -440,10 +440,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/nunnatsa/ginkgolinter"), - linter.NewConfig(golinters.NewGocheckdirectives()). + linter.NewConfig(golinters.NewGocheckcompilerdirectives()). WithSince("v1.51.0"). WithPresets(linter.PresetBugs). - WithURL("https://github.com/leighmcculloch/gocheckdirectives"), + WithURL("https://github.com/leighmcculloch/gocheckcompilerdirectives"), linter.NewConfig(golinters.NewGochecknoglobals()). WithSince("v1.12.0"). diff --git a/test/testdata/gocheckdirectives.go b/test/testdata/gocheckdirectives.go index 6d95d187c314..61bef2d44b5a 100644 --- a/test/testdata/gocheckdirectives.go +++ b/test/testdata/gocheckdirectives.go @@ -1,4 +1,4 @@ -//golangcitest:args -Egocheckdirectives +//golangcitest:args -Egocheckcompilerdirectives package testdata import _ "embed" @@ -14,8 +14,8 @@ var Value string // Problematic cases: -// go:embed // want "go directive contains leading space: // go:embed" +// go:embed // want "compiler directive contains space: // go:embed" -// go:embed // want "go directive contains leading space: // go:embed" +// go:embed // want "compiler directive contains space: // go:embed" -//go:genrate // want "unrecognized go directive: //go:genrate" +//go:genrate // want "compiler directive unrecognized: //go:genrate" From 184fa99f10d61d1326c6a5a9d19ad1f0b8ac9b66 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 20 Jan 2023 08:41:20 -0800 Subject: [PATCH 7/9] Update pkg/golinters/gocheckdirectives.go Co-authored-by: Ludovic Fernandez --- pkg/golinters/gocheckdirectives.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkg/golinters/gocheckdirectives.go b/pkg/golinters/gocheckdirectives.go index 03fff7078121..06e5fdf90f4c 100644 --- a/pkg/golinters/gocheckdirectives.go +++ b/pkg/golinters/gocheckdirectives.go @@ -10,11 +10,6 @@ import ( func NewGocheckcompilerdirectives() *goanalysis.Linter { gocheckcompilerdirectives := checkcompilerdirectives.Analyzer() - // gocheckcompilerdirectives has no config. - linterConfig := map[string]map[string]interface{}{ - gocheckcompilerdirectives.Name: {}, - } - return goanalysis.NewLinter( gocheckcompilerdirectives.Name, gocheckcompilerdirectives.Doc, From b167c74e2c0ab106ba809883744f303c4ee97068 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 20 Jan 2023 08:41:29 -0800 Subject: [PATCH 8/9] Update pkg/golinters/gocheckdirectives.go Co-authored-by: Ludovic Fernandez --- pkg/golinters/gocheckdirectives.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/golinters/gocheckdirectives.go b/pkg/golinters/gocheckdirectives.go index 06e5fdf90f4c..7036a63746da 100644 --- a/pkg/golinters/gocheckdirectives.go +++ b/pkg/golinters/gocheckdirectives.go @@ -14,6 +14,6 @@ func NewGocheckcompilerdirectives() *goanalysis.Linter { gocheckcompilerdirectives.Name, gocheckcompilerdirectives.Doc, []*analysis.Analyzer{gocheckcompilerdirectives}, - linterConfig, + nil, ).WithLoadMode(goanalysis.LoadModeSyntax) } From b984c9943ff3bab63e290b3e99cdccf4a50f638d Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 21 Jan 2023 13:38:58 +0100 Subject: [PATCH 9/9] review --- ...checkdirectives.go => gocheckcompilerdirectives.go} | 10 +++++----- pkg/lint/lintersdb/manager.go | 2 +- ...checkdirectives.go => gocheckcompilerdirectives.go} | 0 3 files changed, 6 insertions(+), 6 deletions(-) rename pkg/golinters/{gocheckdirectives.go => gocheckcompilerdirectives.go} (53%) rename test/testdata/{gocheckdirectives.go => gocheckcompilerdirectives.go} (100%) diff --git a/pkg/golinters/gocheckdirectives.go b/pkg/golinters/gocheckcompilerdirectives.go similarity index 53% rename from pkg/golinters/gocheckdirectives.go rename to pkg/golinters/gocheckcompilerdirectives.go index 7036a63746da..2592c899463b 100644 --- a/pkg/golinters/gocheckdirectives.go +++ b/pkg/golinters/gocheckcompilerdirectives.go @@ -7,13 +7,13 @@ import ( "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" ) -func NewGocheckcompilerdirectives() *goanalysis.Linter { - gocheckcompilerdirectives := checkcompilerdirectives.Analyzer() +func NewGoCheckCompilerDirectives() *goanalysis.Linter { + a := checkcompilerdirectives.Analyzer() return goanalysis.NewLinter( - gocheckcompilerdirectives.Name, - gocheckcompilerdirectives.Doc, - []*analysis.Analyzer{gocheckcompilerdirectives}, + a.Name, + a.Doc, + []*analysis.Analyzer{a}, nil, ).WithLoadMode(goanalysis.LoadModeSyntax) } diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 2f691c4124bb..a1f9e4eff0b2 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -440,7 +440,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { WithPresets(linter.PresetStyle). WithURL("https://github.com/nunnatsa/ginkgolinter"), - linter.NewConfig(golinters.NewGocheckcompilerdirectives()). + linter.NewConfig(golinters.NewGoCheckCompilerDirectives()). WithSince("v1.51.0"). WithPresets(linter.PresetBugs). WithURL("https://github.com/leighmcculloch/gocheckcompilerdirectives"), diff --git a/test/testdata/gocheckdirectives.go b/test/testdata/gocheckcompilerdirectives.go similarity index 100% rename from test/testdata/gocheckdirectives.go rename to test/testdata/gocheckcompilerdirectives.go