nunnatsa / ginkgolinter

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

[BUG] type checker gives false positive for WithTransform + ContainElement #115

Closed LittleFox94 closed 8 months ago

LittleFox94 commented 8 months ago

Describe the bug The new type check linting gives a false positive when using a WithTransform to transform e.g. an []int into an []string together with ContainElement(string):

ginkgo-linter: use ContainElement with different types: Comparing []string with string; either change the expected value type if possible, or use the BeEquivalentTo() matcher, instead of ContainElement() (ginkgolinter)

To Reproduce

Expect([]int{42, 23}).Should(WithTransform(func(v []int) []string {
    ret := make([]string, 0, len(v))
    for _, i := range v {
        ret = append(ret, fmt.Sprintf("%v", i))
    }
    return ret
}, ContainElement("42")))

Expected behavior Using ContainElement(string) on the output of a WithTransform function that returns a []string is correct and the linter should not report an error for that.

Environment:

Additional context

Originally spotted in our CI here, the problematic code being here.

nunnatsa commented 8 months ago

Thanks for letting me know, @LittleFox94!

nunnatsa commented 8 months ago

@LittleFox94 - would you like to review the fix? https://github.com/nunnatsa/ginkgolinter/pull/116

LittleFox94 commented 8 months ago

Heya, sorry for my late reply .. seems to be ok now - thank you :)

nunnatsa commented 8 months ago

The fix is included in golangci-lint version v1.55.2