Releases: nunnatsa/ginkgolinter
v0.15.1
v0.15.0
What's Changed
New rule(s): Wrong Usage of the MatchError
gomega Matcher
The MatchError
gomega matcher asserts an error value (and if it's not nil).
There are four valid formats for using this Matcher:
- error value; e.g.
Expect(err).To(MatchError(anotherErr))
- string, to be equal to the output of the
Error()
method; e.g.Expect(err).To(MatchError("Not Found"))
- A gomega matcher that asserts strings; e.g.
Expect(err).To(MatchError(ContainSubstring("Found")))
- [from v0.29.0] a function that receive a single error parameter and returns a single boolean value. In this format, an additional single string parameter, with the function description, is also required; e.g.
Expect(err).To(MatchError(isNotFound, "is the error is a not found error"))
These four format are checked on runtime, but sometimes it's too late. ginkgolinter performs a static analysis and so it will find these issues on build time.
ginkgolinter checks the following:
- Is the first parameter is one of the four options above.
- That there are no additional parameters passed to the matcher; e.g.
MatchError(isNotFoundFunc, "a valid description" , "not used string")
. In this case, the matcher won't fail on run time, but the additional parameters are not in use and ignored. - If the first parameter is a function with the format of
func(error)bool
, ginkgolinter makes sure that the second parameter exists and its type is string.
Full Changelog: v0.14.1...v0.15.0
v0.14.1
v0.14.0
New Rule: Prevent comparing of value from different types
The Equal
and the BeIdentical
gomega matchers check not only the value, but also the type.
For example:
x := uint(5)
Expect(x).Should(Equal(5))
This assertion will fail in runtime (when running the test). This is not too bad for unit tests, that can be easily run locally and be fixed, but for complex functional or e2e test, it could be hard to debug and it's not always simple to run.
In addition, it can create fals positive tests, for example:
x := uint(5)
Expect(x).ShouldNot(Equal(5))
This test will pass. The value itself is never checked, but only the type.
ginkgolinter now finds these cases and trigger warnings for them.
command line arguments
The new --suppress-type-compare-assertion=true
command line argument will suppress this new rule.
Full Changelog: v0.13.5...v0.14.0
v0.13.5
What's Changed
Improve the focus rule
- forbid also the
FDescribeTable
and theFEntry
focused containers. - forbid the
Focus
individual spec, as inIt("test something", Focus, func(){ Expect(...)... })
Full Changelog: v0.13.3...v0.13.5
v0.13.3
Bug Fixes
Optimize focus-container validation to opt-in
Make the focused container rule to be opt-in. It is now disabled by default and should be enabled by the user.
CLI Flags
- The
--suppress-focus-container
flag is now depracated and ignored. - The new
--forbid-focus-container=true
flag enables the focused container rule.
Full Changelog: v0.13.0...v0.13.3
v0.13.0
New Rule: disallow focus containers
This new rule prevent the leaking of a local debug code to the repo, by forbidding the usage of the ginkgo focus container (FDescribe
, FContext
, FWhen
and FIt
).
new suppress comment
in order to locally suppress this new rule, use the following comment (see more details at the README.md
// ginkgo-linter:ignore-focus-container-warning
new command line flag
--suppress-focus-container=true
- to suppress the new rule
Misc
Docs
fix the version of golangci-lint in the README.md by @chetan-rns
bump golang to 1.20
New Contributors - thank you so much! 🥇
- @chetan-rns made their first contribution in #96
Full Changelog: v0.12.2...v0.13.0
v0.12.2
v0.12.1
v0.12.0
New Rules
Missing Assertion Method
The linter warns when calling an "actual" method (e.g. Expect()
, Eventually()
etc.), without an assertion method (e.g Should()
, NotTo()
etc.)
For example:
// no assertion for the result
Eventually(doSomething).WithTimeout(time.Seconds * 5).WithPolling(time.Milliseconds * 100)
The linter will not suggest a fix for this warning.
This rule cannot be suppressed.
Full Changelog: v0.11.2...v0.12.0