feat: add gocheckcompilerdirectives (#3463)
This commit is contained in:
parent
3cc6373117
commit
d5d671f0bf
@ -2014,6 +2014,7 @@ linters:
|
|||||||
- funlen
|
- funlen
|
||||||
- gci
|
- gci
|
||||||
- ginkgolinter
|
- ginkgolinter
|
||||||
|
- gocheckcompilerdirectives
|
||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
- gochecknoinits
|
- gochecknoinits
|
||||||
- gocognit
|
- gocognit
|
||||||
@ -2123,6 +2124,7 @@ linters:
|
|||||||
- funlen
|
- funlen
|
||||||
- gci
|
- gci
|
||||||
- ginkgolinter
|
- ginkgolinter
|
||||||
|
- gocheckcompilerdirectives
|
||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
- gochecknoinits
|
- gochecknoinits
|
||||||
- gocognit
|
- gocognit
|
||||||
|
1
go.mod
1
go.mod
@ -3,6 +3,7 @@ module github.com/golangci/golangci-lint
|
|||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
4d63.com/gocheckcompilerdirectives v1.1.0
|
||||||
4d63.com/gochecknoglobals v0.1.0
|
4d63.com/gochecknoglobals v0.1.0
|
||||||
github.com/Abirdcfly/dupword v0.0.9
|
github.com/Abirdcfly/dupword v0.0.9
|
||||||
github.com/Antonboom/errname v0.1.7
|
github.com/Antonboom/errname v0.1.7
|
||||||
|
2
go.sum
generated
2
go.sum
generated
@ -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 h1:zeZSRqj5yCg28tCkIV/z/lWbwvNm5qnKVS15PI8nhD0=
|
||||||
4d63.com/gochecknoglobals v0.1.0/go.mod h1:wfdC5ZjKSPr7CybKEcgJhUOgeAQW1+7WcyK8OvUilfo=
|
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=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
19
pkg/golinters/gocheckcompilerdirectives.go
Normal file
19
pkg/golinters/gocheckcompilerdirectives.go
Normal 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)
|
||||||
|
}
|
@ -440,6 +440,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
|
|||||||
WithPresets(linter.PresetStyle).
|
WithPresets(linter.PresetStyle).
|
||||||
WithURL("https://github.com/nunnatsa/ginkgolinter"),
|
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()).
|
linter.NewConfig(golinters.NewGochecknoglobals()).
|
||||||
WithSince("v1.12.0").
|
WithSince("v1.12.0").
|
||||||
WithPresets(linter.PresetStyle).
|
WithPresets(linter.PresetStyle).
|
||||||
|
21
test/testdata/gocheckcompilerdirectives.go
vendored
Normal file
21
test/testdata/gocheckcompilerdirectives.go
vendored
Normal 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"
|
Loading…
x
Reference in New Issue
Block a user