Skip to content

Commit d5d671f

Browse files
feat: add gocheckcompilerdirectives (#3463)
1 parent 3cc6373 commit d5d671f

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

.golangci.reference.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,7 @@ linters:
20142014
- funlen
20152015
- gci
20162016
- ginkgolinter
2017+
- gocheckcompilerdirectives
20172018
- gochecknoglobals
20182019
- gochecknoinits
20192020
- gocognit
@@ -2123,6 +2124,7 @@ linters:
21232124
- funlen
21242125
- gci
21252126
- ginkgolinter
2127+
- gocheckcompilerdirectives
21262128
- gochecknoglobals
21272129
- gochecknoinits
21282130
- gocognit

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/golangci/golangci-lint
33
go 1.19
44

55
require (
6+
4d63.com/gocheckcompilerdirectives v1.1.0
67
4d63.com/gochecknoglobals v0.1.0
78
github.com/Abirdcfly/dupword v0.0.9
89
github.com/Antonboom/errname v0.1.7

go.sum

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package golinters
2+
3+
import (
4+
"4d63.com/gocheckcompilerdirectives/checkcompilerdirectives"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
)
9+
10+
func NewGoCheckCompilerDirectives() *goanalysis.Linter {
11+
a := checkcompilerdirectives.Analyzer()
12+
13+
return goanalysis.NewLinter(
14+
a.Name,
15+
a.Doc,
16+
[]*analysis.Analyzer{a},
17+
nil,
18+
).WithLoadMode(goanalysis.LoadModeSyntax)
19+
}

pkg/lint/lintersdb/manager.go

+5
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,11 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
440440
WithPresets(linter.PresetStyle).
441441
WithURL("https://github.com/nunnatsa/ginkgolinter"),
442442

443+
linter.NewConfig(golinters.NewGoCheckCompilerDirectives()).
444+
WithSince("v1.51.0").
445+
WithPresets(linter.PresetBugs).
446+
WithURL("https://github.com/leighmcculloch/gocheckcompilerdirectives"),
447+
443448
linter.NewConfig(golinters.NewGochecknoglobals()).
444449
WithSince("v1.12.0").
445450
WithPresets(linter.PresetStyle).
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//golangcitest:args -Egocheckcompilerdirectives
2+
package testdata
3+
4+
import _ "embed"
5+
6+
// Okay cases:
7+
8+
//go:generate echo hello world
9+
10+
//go:embed
11+
var Value string
12+
13+
//go:
14+
15+
// Problematic cases:
16+
17+
// go:embed // want "compiler directive contains space: // go:embed"
18+
19+
// go:embed // want "compiler directive contains space: // go:embed"
20+
21+
//go:genrate // want "compiler directive unrecognized: //go:genrate"

0 commit comments

Comments
 (0)