Skip to content

Commit f837070

Browse files
build(deps): bump github.com/nunnatsa/ginkgolinter from 0.15.2 to 0.16.0 (#4530)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent e3ed3ba commit f837070

14 files changed

+240
-205
lines changed

.golangci.next.reference.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,18 +477,32 @@ linters-settings:
477477
# Default: false
478478
suppress-async-assertion: true
479479

480-
# Suppress warning for comparing values from different types, like int32 and uint32
480+
# Suppress warning for comparing values from different types, like `int32` and `uint32`
481481
# Default: false
482482
suppress-type-compare-assertion: true
483483

484-
# Trigger warning for ginkgo focus containers like FDescribe, FContext, FWhen or FIt
484+
# Trigger warning for ginkgo focus containers like `FDescribe`, `FContext`, `FWhen` or `FIt`
485485
# Default: false
486486
forbid-focus-container: true
487487

488488
# Don't trigger warnings for HaveLen(0)
489489
# Default: false
490490
allow-havelen-zero: true
491491

492+
# Force using `Expect` with `To`, `ToNot` or `NotTo`.
493+
# Reject using `Expect` with `Should` or `ShouldNot`.
494+
# Default: false
495+
force-expect-to: true
496+
497+
# Best effort validation of async intervals (timeout and polling).
498+
# Ignored the suppress-async-assertion is true.
499+
# Default: false
500+
validate-async-intervals: true
501+
502+
# Trigger a warning for variable assignments in ginkgo containers like `Describe`, `Context` and `When`, instead of in `BeforeEach()`.
503+
# Default: false
504+
forbid-spec-pollution: true
505+
492506
gocognit:
493507
# Minimal code complexity to report.
494508
# Default: 30 (but we recommend 10-20)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ require (
7979
github.com/nakabonne/nestif v0.3.1
8080
github.com/nishanths/exhaustive v0.12.0
8181
github.com/nishanths/predeclared v0.2.2
82-
github.com/nunnatsa/ginkgolinter v0.15.2
82+
github.com/nunnatsa/ginkgolinter v0.16.0
8383
github.com/polyfloyd/go-errorlint v1.4.8
8484
github.com/quasilyte/go-ruleguard/dsl v0.3.22
8585
github.com/ryancurrah/gomodguard v1.3.0
@@ -186,7 +186,7 @@ require (
186186
go.uber.org/atomic v1.7.0 // indirect
187187
go.uber.org/multierr v1.6.0 // indirect
188188
go.uber.org/zap v1.24.0 // indirect
189-
golang.org/x/exp/typeparams v0.0.0-20240213143201-ec583247a57a // indirect
189+
golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect
190190
golang.org/x/mod v0.16.0 // indirect
191191
golang.org/x/sync v0.6.0 // indirect
192192
golang.org/x/sys v0.18.0 // indirect

go.sum

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

jsonschema/golangci.next.jsonschema.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,21 @@
10791079
"description": "Don't trigger warnings for HaveLen(0).",
10801080
"type": "boolean",
10811081
"default": false
1082+
},
1083+
"force-expect-to": {
1084+
"description": "Force using `Expect` with `To`, `ToNot` or `NotTo`",
1085+
"type": "boolean",
1086+
"default": false
1087+
},
1088+
"validate-async-intervals": {
1089+
"description": "Best effort validation of async intervals (timeout and polling).",
1090+
"type": "boolean",
1091+
"default": false
1092+
},
1093+
"forbid-spec-pollution": {
1094+
"description": "Trigger a warning for variable assignments in ginkgo containers like `Describe`, `Context` and `When`, instead of in `BeforeEach()`.",
1095+
"type": "boolean",
1096+
"default": false
10821097
}
10831098
}
10841099
},

pkg/config/linters_settings.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@ type GinkgoLinterSettings struct {
467467
SuppressTypeCompareWarning bool `mapstructure:"suppress-type-compare-assertion"`
468468
ForbidFocusContainer bool `mapstructure:"forbid-focus-container"`
469469
AllowHaveLenZero bool `mapstructure:"allow-havelen-zero"`
470+
ForceExpectTo bool `mapstructure:"force-expect-to"`
471+
ValidateAsyncIntervals bool `mapstructure:"validate-async-intervals"`
472+
ForbidSpecPollution bool `mapstructure:"forbid-spec-pollution"`
470473
}
471474

472475
type GocognitSettings struct {

pkg/golinters/ginkgolinter.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ import (
88
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
99
)
1010

11-
func NewGinkgoLinter(cfg *config.GinkgoLinterSettings) *goanalysis.Linter {
11+
func NewGinkgoLinter(settings *config.GinkgoLinterSettings) *goanalysis.Linter {
1212
a := ginkgolinter.NewAnalyzer()
1313

1414
cfgMap := make(map[string]map[string]any)
15-
if cfg != nil {
15+
if settings != nil {
1616
cfgMap[a.Name] = map[string]any{
17-
"suppress-len-assertion": cfg.SuppressLenAssertion,
18-
"suppress-nil-assertion": cfg.SuppressNilAssertion,
19-
"suppress-err-assertion": cfg.SuppressErrAssertion,
20-
"suppress-compare-assertion": cfg.SuppressCompareAssertion,
21-
"suppress-async-assertion": cfg.SuppressAsyncAssertion,
22-
"suppress-type-compare-assertion": cfg.SuppressTypeCompareWarning,
23-
"forbid-focus-container": cfg.ForbidFocusContainer,
24-
"allow-havelen-0": cfg.AllowHaveLenZero,
17+
"suppress-len-assertion": settings.SuppressLenAssertion,
18+
"suppress-nil-assertion": settings.SuppressNilAssertion,
19+
"suppress-err-assertion": settings.SuppressErrAssertion,
20+
"suppress-compare-assertion": settings.SuppressCompareAssertion,
21+
"suppress-async-assertion": settings.SuppressAsyncAssertion,
22+
"suppress-type-compare-assertion": settings.SuppressTypeCompareWarning,
23+
"forbid-focus-container": settings.ForbidFocusContainer,
24+
"allow-havelen-0": settings.AllowHaveLenZero,
25+
"force-expect-to": settings.ForceExpectTo,
26+
"forbid-spec-pollution": settings.ForbidSpecPollution,
27+
"validate-async-intervals": settings.ValidateAsyncIntervals,
2528
}
2629
}
2730

test/testdata/ginkgolinter/ginkgolinter.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,58 @@ func LenUsecase() {
1414
Expect(fakeVarUnderTest).Should(BeEmpty()) // valid
1515
Expect(fakeVarUnderTest).ShouldNot(HaveLen(5)) // valid
1616

17-
Expect(len(fakeVarUnderTest)).Should(Equal(0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.Should\\(BeEmpty\\(\\)\\). instead"
18-
Expect(len(fakeVarUnderTest)).ShouldNot(Equal(2)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ShouldNot\\(HaveLen\\(2\\)\\). instead"
19-
Expect(len(fakeVarUnderTest)).To(BeNumerically("==", 0)) // // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.To\\(BeEmpty\\(\\)\\). instead"
17+
Expect(len(fakeVarUnderTest)).Should(Equal(0)) // want "ginkgo-linter: wrong length assertion. Consider using .Expect\\(fakeVarUnderTest\\)\\.Should\\(BeEmpty\\(\\)\\)"
18+
Expect(len(fakeVarUnderTest)).ShouldNot(Equal(2)) // want "ginkgo-linter: wrong length assertion. Consider using .Expect\\(fakeVarUnderTest\\)\\.ShouldNot\\(HaveLen\\(2\\)\\)"
19+
Expect(len(fakeVarUnderTest)).To(BeNumerically("==", 0)) // // want "ginkgo-linter: wrong length assertion. Consider using .Expect\\(fakeVarUnderTest\\)\\.To\\(BeEmpty\\(\\)\\)"
2020

2121
fakeVarUnderTest = append(fakeVarUnderTest, 3)
22-
Expect(len(fakeVarUnderTest)).ShouldNot(Equal(0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ShouldNot\\(BeEmpty\\(\\)\\). instead"
23-
Expect(len(fakeVarUnderTest)).Should(Equal(1)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.Should\\(HaveLen\\(1\\)\\). instead"
24-
Expect(len(fakeVarUnderTest)).To(BeNumerically(">", 0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\). instead"
25-
Expect(len(fakeVarUnderTest)).To(BeNumerically(">=", 1)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\). instead"
26-
Expect(len(fakeVarUnderTest)).To(BeNumerically("!=", 0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\). instead"
22+
Expect(len(fakeVarUnderTest)).ShouldNot(Equal(0)) // want "ginkgo-linter: wrong length assertion. Consider using .Expect\\(fakeVarUnderTest\\)\\.ShouldNot\\(BeEmpty\\(\\)\\)"
23+
Expect(len(fakeVarUnderTest)).Should(Equal(1)) // want "ginkgo-linter: wrong length assertion. Consider using .Expect\\(fakeVarUnderTest\\)\\.Should\\(HaveLen\\(1\\)\\)"
24+
Expect(len(fakeVarUnderTest)).To(BeNumerically(">", 0)) // want "ginkgo-linter: wrong length assertion. Consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\)"
25+
Expect(len(fakeVarUnderTest)).To(BeNumerically(">=", 1)) // want "ginkgo-linter: wrong length assertion. Consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\)"
26+
Expect(len(fakeVarUnderTest)).To(BeNumerically("!=", 0)) // want "ginkgo-linter: wrong length assertion. Consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\)"
2727
}
2828

2929
func NilUsecase() {
3030
y := 5
3131
x := &y
32-
Expect(x == nil).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\). instead"
33-
Expect(nil == x).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\). instead"
34-
Expect(x != nil).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.ToNot\\(BeNil\\(\\)\\). instead"
35-
Expect(x == nil).To(BeTrue()) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\). instead"
36-
Expect(x == nil).To(BeFalse()) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.ToNot\\(BeNil\\(\\)\\). instead"
32+
Expect(x == nil).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion. Consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\)"
33+
Expect(nil == x).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion. Consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\)"
34+
Expect(x != nil).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion. Consider using .Expect\\(x\\)\\.ToNot\\(BeNil\\(\\)\\)"
35+
Expect(x == nil).To(BeTrue()) // want "ginkgo-linter: wrong nil assertion. Consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\)"
36+
Expect(x == nil).To(BeFalse()) // want "ginkgo-linter: wrong nil assertion. Consider using .Expect\\(x\\)\\.ToNot\\(BeNil\\(\\)\\)"
3737
}
3838
func BooleanUsecase() {
3939
x := true
40-
Expect(x).To(Equal(true)) // want "ginkgo-linter: wrong boolean assertion; consider using .Expect\\(x\\)\\.To\\(BeTrue\\(\\)\\). instead"
40+
Expect(x).To(Equal(true)) // want "ginkgo-linter: wrong boolean assertion. Consider using .Expect\\(x\\)\\.To\\(BeTrue\\(\\)\\)"
4141
x = false
42-
Expect(x).To(Equal(false)) // want "ginkgo-linter: wrong boolean assertion; consider using .Expect\\(x\\)\\.To\\(BeFalse\\(\\)\\). instead"
42+
Expect(x).To(Equal(false)) // want "ginkgo-linter: wrong boolean assertion. Consider using .Expect\\(x\\)\\.To\\(BeFalse\\(\\)\\)"
4343
}
4444

4545
func ErrorUsecase() {
4646
err := errors.New("fake error")
4747
funcReturnsErr := func() error { return err }
4848

49-
Expect(err).To(BeNil()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.ToNot\\(HaveOccurred\\(\\)\\). instead"
50-
Expect(err == nil).To(Equal(true)) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.ToNot\\(HaveOccurred\\(\\)\\). instead"
51-
Expect(err == nil).To(BeFalse()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.To\\(HaveOccurred\\(\\)\\). instead"
52-
Expect(err != nil).To(BeTrue()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.To\\(HaveOccurred\\(\\)\\). instead"
53-
Expect(funcReturnsErr()).To(BeNil()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(funcReturnsErr\\(\\)\\)\\.To\\(Succeed\\(\\)\\). instead"
49+
Expect(err).To(BeNil()) // want "ginkgo-linter: wrong error assertion. Consider using .Expect\\(err\\)\\.ToNot\\(HaveOccurred\\(\\)\\)"
50+
Expect(err == nil).To(Equal(true)) // want "ginkgo-linter: wrong error assertion. Consider using .Expect\\(err\\)\\.ToNot\\(HaveOccurred\\(\\)\\)"
51+
Expect(err == nil).To(BeFalse()) // want "ginkgo-linter: wrong error assertion. Consider using .Expect\\(err\\)\\.To\\(HaveOccurred\\(\\)\\)"
52+
Expect(err != nil).To(BeTrue()) // want "ginkgo-linter: wrong error assertion. Consider using .Expect\\(err\\)\\.To\\(HaveOccurred\\(\\)\\)"
53+
Expect(funcReturnsErr()).To(BeNil()) // want "ginkgo-linter: wrong error assertion. Consider using .Expect\\(funcReturnsErr\\(\\)\\)\\.To\\(Succeed\\(\\)\\)"
5454
}
5555

5656
func HaveLen0Usecase() {
5757
x := make([]string, 0)
58-
Expect(x).To(HaveLen(0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(x\\)\\.To\\(BeEmpty\\(\\)\\). instead"
58+
Expect(x).To(HaveLen(0)) // want "ginkgo-linter: wrong length assertion. Consider using .Expect\\(x\\)\\.To\\(BeEmpty\\(\\)\\)"
5959
}
6060

6161
func WrongComparisonUsecase() {
6262
x := 8
63-
Expect(x == 8).To(BeTrue()) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(x\\)\\.To\\(Equal\\(8\\)\\). instead"
64-
Expect(x < 9).To(BeTrue()) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(x\\)\\.To\\(BeNumerically\\(\"<\", 9\\)\\). instead"
65-
Expect(x < 7).To(Equal(false)) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(x\\)\\.ToNot\\(BeNumerically\\(\"<\", 7\\)\\). instead"
63+
Expect(x == 8).To(BeTrue()) // want "ginkgo-linter: wrong comparison assertion. Consider using .Expect\\(x\\)\\.To\\(Equal\\(8\\)\\)"
64+
Expect(x < 9).To(BeTrue()) // want "ginkgo-linter: wrong comparison assertion. Consider using .Expect\\(x\\)\\.To\\(BeNumerically\\(\"<\", 9\\)\\)"
65+
Expect(x < 7).To(Equal(false)) // want "ginkgo-linter: wrong comparison assertion. Consider using .Expect\\(x\\)\\.ToNot\\(BeNumerically\\(\"<\", 7\\)\\)"
6666

6767
p1, p2 := &x, &x
68-
Expect(p1 == p2).To(Equal(true)) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(p1\\).To\\(BeIdenticalTo\\(p2\\)\\). instead"
68+
Expect(p1 == p2).To(Equal(true)) // want "ginkgo-linter: wrong comparison assertion. Consider using .Expect\\(p1\\).To\\(BeIdenticalTo\\(p2\\)\\)"
6969
}
7070

7171
func slowInt() int {
@@ -75,7 +75,7 @@ func slowInt() int {
7575

7676
func WrongEventuallyWithFunction() {
7777
Eventually(slowInt).Should(Equal(42)) // valid
78-
Eventually(slowInt()).Should(Equal(42)) // want "ginkgo-linter: use a function call in Eventually. This actually checks nothing, because Eventually receives the function returned value, instead of function itself, and this value is never changed; consider using .Eventually\\(slowInt\\)\\.Should\\(Equal\\(42\\)\\). instead"
78+
Eventually(slowInt()).Should(Equal(42)) // want "ginkgo-linter: use a function call in Eventually. This actually checks nothing, because Eventually receives the function returned value, instead of function itself, and this value is never changed. Consider using .Eventually\\(slowInt\\)\\.Should\\(Equal\\(42\\)\\)"
7979
}
8080

8181
var _ = FDescribe("Should warn for focused containers", func() {

0 commit comments

Comments
 (0)