From d5d671f0bf82f5047e118a69ac0a34d4c148d868 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Sat, 21 Jan 2023 04:54:17 -0800 Subject: [PATCH] feat: add gocheckcompilerdirectives (#3463) --- .golangci.reference.yml | 2 ++ go.mod | 1 + go.sum | 2 ++ pkg/golinters/gocheckcompilerdirectives.go | 19 +++++++++++++++++++ pkg/lint/lintersdb/manager.go | 5 +++++ test/testdata/gocheckcompilerdirectives.go | 21 +++++++++++++++++++++ 6 files changed, 50 insertions(+) create mode 100644 pkg/golinters/gocheckcompilerdirectives.go create mode 100644 test/testdata/gocheckcompilerdirectives.go diff --git a/.golangci.reference.yml b/.golangci.reference.yml index bc30cd62..efd9b770 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -2014,6 +2014,7 @@ linters: - funlen - gci - ginkgolinter + - gocheckcompilerdirectives - gochecknoglobals - gochecknoinits - gocognit @@ -2123,6 +2124,7 @@ linters: - funlen - gci - ginkgolinter + - gocheckcompilerdirectives - gochecknoglobals - gochecknoinits - gocognit diff --git a/go.mod b/go.mod index 4848f9bc..aa3050ed 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 diff --git a/go.sum b/go.sum index 76332121..85628a87 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= diff --git a/pkg/golinters/gocheckcompilerdirectives.go b/pkg/golinters/gocheckcompilerdirectives.go new file mode 100644 index 00000000..2592c899 --- /dev/null +++ b/pkg/golinters/gocheckcompilerdirectives.go @@ -0,0 +1,19 @@ +package golinters + +import ( + "4d63.com/gocheckcompilerdirectives/checkcompilerdirectives" + "golang.org/x/tools/go/analysis" + + "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" +) + +func NewGoCheckCompilerDirectives() *goanalysis.Linter { + a := checkcompilerdirectives.Analyzer() + + return goanalysis.NewLinter( + 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 6ea531b8..a1f9e4ef 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.NewGoCheckCompilerDirectives()). + WithSince("v1.51.0"). + WithPresets(linter.PresetBugs). + WithURL("https://github.com/leighmcculloch/gocheckcompilerdirectives"), + linter.NewConfig(golinters.NewGochecknoglobals()). WithSince("v1.12.0"). WithPresets(linter.PresetStyle). diff --git a/test/testdata/gocheckcompilerdirectives.go b/test/testdata/gocheckcompilerdirectives.go new file mode 100644 index 00000000..61bef2d4 --- /dev/null +++ b/test/testdata/gocheckcompilerdirectives.go @@ -0,0 +1,21 @@ +//golangcitest:args -Egocheckcompilerdirectives +package testdata + +import _ "embed" + +// Okay cases: + +//go:generate echo hello world + +//go:embed +var Value string + +//go: + +// Problematic cases: + +// go:embed // want "compiler directive contains space: // go:embed" + +// go:embed // want "compiler directive contains space: // go:embed" + +//go:genrate // want "compiler directive unrecognized: //go:genrate"