v0.16.0
What's Changed
New Rules
Optional Rule: Force Expect
with To
[STYLE]
Trigger warning when using Expect
with Should
or ShouldNot`; e.g.
Expect(err).ShouldNot(HaveOccurred())
Should be
Expect(err).ToNot(HaveOccurred())
This rule is optional. Add the --force-expect-to=true
to enable this rule.
Rule: cap assertion [STYLE]
Very similar to the len
rule. The linter triggers a warning when using
Expect(cap(slice)).To(Equal(3))
Instead, the linter suggests
Expect(slice).To(HaveCap(3))
This rule is now part of the len
rule. It uses the same configurations:
- enabled by default
- To suppress this warning, use the
--suppress-len-assertion=true
flag. - To suppress this warning for a file, add a comment in the top of the file:
// ginkgo-linter:ignore-len-assert-warning
- To suppress this warning for a specific expression, add the comment above the expression:
// ginkgo-linter:ignore-len-assert-warning Expect(cap(slice)).To(Equal(3))
Optional Rule: validate async intervals [BUG and STYLE]
Note: This rule works as best-effort. It can't catch all cases.
This rule is disable by default. Use the --validate-async-intervals=true
flag to enable it. Also, the --suppress-async-assertion
flag must not be set to true. In this case, this rule is disabled.
This rule is actually three sub-rules
Timeout Must be Longer than Polling [BUG]
In async assertions (Eventually
or Consistently
), the linter checks that the timeout is not shorter than the polling interval.
For example:
Eventually(..., time.Millisecond * 500 /*timeout*/, 10 * time.Second /*polling*/)
// or:
Eventually(...).WithTimeout(time.Millisecond * 500).WithPolling(10 * time.Second)
// or any combination of the above
Avoid using non time.Duration
for Timeout and Polling [STYLE]
ginkgo async functions support many forms for duration, when passing timeout and polling arguments. However, this is an old API, that is mostly there for backward compatible.
The linter now trigger a warning if the time interval are not of type time.Duration
.
For example:
Eventually(..., 20 /*timeout of 20 seconds*/, "2s" /*polling of two seconds*/)
This rule support a very limited auto-fix option, when the value is an integer, or an integer const.
Avoid redefinition of timeout or polling [STYLE]
The linter only allow up to one polling and up to one timeout; e.g.
Eventually(..., time.Millisecond * 500 /*timeout*/, 10 * time.Second /*polling*/).WithTimeout(time.Millisecond * 500).WithPolling(10 * time.Second)
// or any combination of the above
Optional Rule: Avoid spec Pollution [BUG/STYLE]
To avoid test spec pollution, avoid assigning to variable within container nodes; see more info in ginkgo documentation.
The linter now enforce this rule; e.g.
var _ = Describe("spec pollution in Describe", func(){
x := "spec pollution"
...
Context("spec pollution in Context", func() {
y := "another spec pollution"
...
})
})
It should be done more like this:
var _ = Describe("spec pollution in Describe", func(){
var x string
BeforeEach(func(){
x = "now no spec pollution"
})
...
Context("spec pollution in Context", func() {
var y string
...
BeforeEach(func(){
y = "now no spec pollution"
})
...
})
})
This rule is disable by default. use the --forbid-spec-pollution=true
flag to enable it.
Full Changelog: v0.15.2...v0.16.0