nunnatsa / ginkgolinter

golang linter for ginkgo and gomega
MIT License
24 stars 6 forks source link

New Rule: should not compare two different types #110

Closed nunnatsa closed 9 months ago

nunnatsa commented 9 months ago

The Equal and the BeIdentical matchers also check the type, not only the value.

The following code will fail in runtime:

x := 5 // x is int
Expect(x).Should(Eqaul(uint(5)) // x and uint(5) are with different
types

When using negative checks, it's even worse, because we get a fale positive:

x := 5
Expect(x).ToNot(Equal(uint(5))

To solve this problem, we want to find these errors before running the tests and failing on runtime. This is even more important for e2e or functional tests, where we sometimes can't run them on the local development environment.

This PR adds a new rule to the linter, to find comaprison of values from different types.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Checklist:

@pohly

fixes #109

github-actions[bot] commented 9 months ago

Pull Request Test Coverage Report for Build 6369713012


Changes Missing Coverage Covered Lines Changed/Added Lines %
types/config.go 8 10 80.0%
ginkgo_linter.go 61 72 84.72%
<!-- Total: 69 82 84.15% -->
Totals Coverage Status
Change from base Build 6141414406: -0.1%
Covered Lines: 986
Relevant Lines: 1176

💛 - Coveralls