feat: add gocheckcompilerdirectives (#3463)

This commit is contained in:
Leigh McCulloch 2023-01-21 04:54:17 -08:00 committed by GitHub
parent 3cc6373117
commit d5d671f0bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 0 deletions

View File

@ -2014,6 +2014,7 @@ linters:
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gocognit
@ -2123,6 +2124,7 @@ linters:
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gocognit

1
go.mod
View File

@ -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

2
go.sum generated
View File

@ -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=

View File

@ -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)
}

View File

@ -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).

View File

@ -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"