Linter for gomega assertions.
- Checks whether you're not mixing Ω-notation with Expect-notation (which compiles, but looks weird).
- Recommends most appropriate matcher for checking nilness (
BeNil
/Succeed
/HaveOccurred
), depending on context.
Uses standard linter interface based on golang.org/x/tools/go/analysis.
$ gomegalint -c 0 github.com/xxx/yyy/pkg/...
…/zzz.go:25:3: unidiomatic matcher: consider using HaveOccurred instead of BeNil in this assertion
25 Expect(err).Should(BeNil())
…/zzz.go:25:3: inconsistent assertion style (Expect + Should)
25 Expect(err).Should(BeNil())
All warnings are auto-fixable with the -fix
flag!
$ gomegalint -fix github.com/xxx/yyy/pkg/...
This applies the following suggestion:
- Expect(err).Should(BeNil())
+ Expect(err).NotTo(HaveOccurred())
go install github.com/krdln/gomegalint@latest