Skip to content

Commit

Permalink
feat: add gocheckcompilerdirectives (golangci#3463)
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored and SeigeC committed Apr 4, 2023
1 parent 7cff1b2 commit 3cddd6e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,7 @@ linters:
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gocognit
Expand Down Expand Up @@ -2148,6 +2149,7 @@ linters:
- funlen
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gocognit
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pkg/golinters/gocheckcompilerdirectives.go
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 5 additions & 0 deletions pkg/lint/lintersdb/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
21 changes: 21 additions & 0 deletions test/testdata/gocheckcompilerdirectives.go
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 3cddd6e

Please sign in to comment.