Releases: nunnatsa/ginkgolinter
v0.11.2
v0.11.1
Release v0.11.0
Changes
New linter rule
Compare pointer to value
The linter warns when comparing a pointer with a value. These comparisons are always wrong and will always fail.
For example:
num := 5
...
pNum := &num
...
Expect(pNum).ShouldNot(Equal(6))
The linter will suggest to use this instead:
Expect(pNum).ShouldNot(HaveValue(Equal(6)))
v0.10.0
This new version brings some new additions:
New Linter Rule:
Function Call in async assertions
The linter now warns about using Eventually
or Consistently
with a function call. This is because when doing that, Eventually
checks the same returned value again and again, instead of polling by calling the function.
For example:
func slowInt() int {
time.Sleep(time.Second)
return 42
}
It("should test that slowInt returns 42, eventually", func() {
Eventually(slowInt()).WithPolling(time.Millisecond * 100).WithTimeout(time.Second * 2).Equal(42)
})
In the above code, Eventually receives 42 as its argument. Then it polls this value to check if it equal
42. What we really wanted here is:
It("should test that slowInt returns 42, eventually", func() {
Eventually(slowInt).WithPolling(time.Millisecond * 100).WithTimeout(time.Second * 2).Equal(42)
})
Now, Eventually
calls the function until it returns the required value.
Note: The linter ignores function calls that return a function or a channel.
To suppress this warning entirely, add the --suppress-async-assertion=true
command line flag, or the ginkgo-linter:ignore-async-assert-warning
comment.
Improvements and Bug Fixes
Bug Fix: len() comparison
When comparing len() result with a number; e.g.
Expect(len(x) == 5).Should(BeTrue())
the linter used to wrongly fix suggested to replace to
Expect(len(x)).To(Equal(5))
which is also a wrong pattern.
Now, the linter will suggest:
Expect(x).To(HaveLen(5))
Avoid double negative assertions
For patterns like
Expect(boolVal).ShouldNot(Equal(false))
or
Expect(boolVal).ShouldNot(BeFalse())
the linter will suggest
Expect(boolVal).Should(BeTrue())
Support the WithOffset() method
The linter used to ignore patterns like
Expect(len(x)).WithOffset(1).Should(Equal(3))
Now, the linter will catch these patterns as well. For the above code, the linter will suggest
Expect(x).WithOffset(1).Should(HaveLen(3))
v0.9.0
This new version brings some new additions:
New Linter Rules
HaveLen()
matcher with a value of 0 (HaveLen(0)
), will trigger a warning that will suggest to replace this matcher withBeEmpty()
.- Assertion of a comparison and a boolean matcher will trigger a warning that will suggest to use the a better matcher, like
BeEqual()
For example:
Expect(x == 1).To(BeTrue()) // ===> Expect(x).To(Equal(1))
Expect(x == 0).To(Equal(false)) // ===> Expect(x).ToNot(BeZero())
Expect(x > y).To(BeTrue()) // ===> Expect(x).To(BeNumerically(">", y))
and so on.
New Executable's flags
--allow-havelen-0=true
: if this flag is set, the linter won't trigger warnings forHaveLen(0)
--suppress-compare-assertion=true
: if this flag is set, the linter won't trigger warnings for wrong boolean comparisons.
New suppress comment
Adding the // ginkgo-linter:ignore-compare-assert-warning
comment, will suppress the wrong comparison warning for a specific file or line. See more details at the README.md file
Release v0.8.1
Tiny fix: go mod tidy
v0.8.0
v0.7.1
v0.7.0
v0.6.0
This release includes some documentation fixes.
It is also fixes GO-2022-0493