Skip to content

Commit 7db1370

Browse files
nunnatsaSeigeC
authored andcommitted
Add the ginkgolinter linter (golangci#3369)
1 parent 9e9fc8d commit 7db1370

17 files changed

+309
-1
lines changed

.golangci.reference.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,21 @@ linters-settings:
402402
# Default: false
403403
custom-order: true
404404

405+
ginkgolinter:
406+
# Suppress the wrong length assertion warning.
407+
# Default: false
408+
suppress-len-assertion: true
409+
410+
# Suppress the wrong nil assertion warning.
411+
# Default: false
412+
suppress-nil-assertion: true
413+
414+
# Suppress the wrong error assertion warning.
415+
# Default: false
416+
suppress-err-assertion: true
417+
405418
gocognit:
406-
# Minimal code complexity to report
419+
# Minimal code complexity to report.
407420
# Default: 30 (but we recommend 10-20)
408421
min-complexity: 10
409422

@@ -2014,6 +2027,7 @@ linters:
20142027
- forcetypeassert
20152028
- funlen
20162029
- gci
2030+
- ginkgolinter
20172031
- gochecknoglobals
20182032
- gochecknoinits
20192033
- gocognit
@@ -2121,6 +2135,7 @@ linters:
21212135
- forcetypeassert
21222136
- funlen
21232137
- gci
2138+
- ginkgolinter
21242139
- gochecknoglobals
21252140
- gochecknoinits
21262141
- gocognit

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ require (
7272
github.com/nakabonne/nestif v0.3.1
7373
github.com/nishanths/exhaustive v0.9.3
7474
github.com/nishanths/predeclared v0.2.2
75+
github.com/nunnatsa/ginkgolinter v0.6.0
7576
github.com/pkg/errors v0.9.1
7677
github.com/polyfloyd/go-errorlint v1.0.6
7778
github.com/quasilyte/go-ruleguard/dsl v0.3.21

go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/linters_settings.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ type LintersSettings struct {
150150
Forbidigo ForbidigoSettings
151151
Funlen FunlenSettings
152152
Gci GciSettings
153+
GinkgoLinter GinkgoLinterSettings
153154
Gocognit GocognitSettings
154155
Goconst GoConstSettings
155156
Gocritic GoCriticSettings
@@ -321,6 +322,12 @@ type GciSettings struct {
321322
CustomOrder bool `mapstructure:"custom-order"`
322323
}
323324

325+
type GinkgoLinterSettings struct {
326+
SuppressLenAssertion bool `mapstructure:"suppress-len-assertion"`
327+
SuppressNilAssertion bool `mapstructure:"suppress-nil-assertion"`
328+
SuppressErrAssertion bool `mapstructure:"suppress-err-assertion"`
329+
}
330+
324331
type GocognitSettings struct {
325332
MinComplexity int `mapstructure:"min-complexity"`
326333
}

pkg/golinters/ginkgolinter.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package golinters
2+
3+
import (
4+
"github.com/nunnatsa/ginkgolinter"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/config"
8+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
9+
)
10+
11+
func NewGinkgoLinter(cfg *config.GinkgoLinterSettings) *goanalysis.Linter {
12+
a := ginkgolinter.NewAnalyzer()
13+
14+
cfgMap := make(map[string]map[string]interface{})
15+
if cfg != nil {
16+
cfgMap[a.Name] = map[string]interface{}{
17+
"suppress-len-assertion": cfg.SuppressLenAssertion,
18+
"suppress-nil-assertion": cfg.SuppressNilAssertion,
19+
"suppress-err-assertion": cfg.SuppressErrAssertion,
20+
}
21+
}
22+
23+
return goanalysis.NewLinter(
24+
a.Name,
25+
a.Doc,
26+
[]*analysis.Analyzer{a},
27+
cfgMap,
28+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
29+
}

pkg/lint/lintersdb/manager.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
118118
forbidigoCfg *config.ForbidigoSettings
119119
funlenCfg *config.FunlenSettings
120120
gciCfg *config.GciSettings
121+
ginkgolinterCfg *config.GinkgoLinterSettings
121122
gocognitCfg *config.GocognitSettings
122123
goconstCfg *config.GoConstSettings
123124
gocriticCfg *config.GoCriticSettings
@@ -194,6 +195,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
194195
forbidigoCfg = &m.cfg.LintersSettings.Forbidigo
195196
funlenCfg = &m.cfg.LintersSettings.Funlen
196197
gciCfg = &m.cfg.LintersSettings.Gci
198+
ginkgolinterCfg = &m.cfg.LintersSettings.GinkgoLinter
197199
gocognitCfg = &m.cfg.LintersSettings.Gocognit
198200
goconstCfg = &m.cfg.LintersSettings.Goconst
199201
gocriticCfg = &m.cfg.LintersSettings.Gocritic
@@ -430,6 +432,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
430432
WithPresets(linter.PresetFormatting, linter.PresetImport).
431433
WithURL("https://github.com/daixiang0/gci"),
432434

435+
linter.NewConfig(golinters.NewGinkgoLinter(ginkgolinterCfg)).
436+
WithSince("v1.51.0").
437+
WithLoadForGoAnalysis().
438+
WithPresets(linter.PresetStyle).
439+
WithURL("https://github.com/nunnatsa/ginkgolinter"),
440+
433441
linter.NewConfig(golinters.NewGochecknoglobals()).
434442
WithSince("v1.12.0").
435443
WithPresets(linter.PresetStyle).

test/linters_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestTypecheck(t *testing.T) {
3030
func TestSourcesFromTestdataSubDir(t *testing.T) {
3131
subDirs := []string{
3232
"loggercheck",
33+
"ginkgolinter",
3334
}
3435

3536
for _, dir := range subDirs {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
linters-settings:
2+
ginkgolinter: {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
ginkgolinter:
3+
suppress-err-assertion: true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
ginkgolinter:
3+
suppress-len-assertion: true

0 commit comments

Comments
 (0)