Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LittleFox94 opened this issue Oct 27, 2023 · 4 comments · Fixed by #116
Closed

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

LittleFox94 opened this issue Oct 27, 2023 · 4 comments · Fixed by #116
Assignees
Labels
bug Something isn't working

Comments

@LittleFox94
Copy link

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:

  • OS: Linux
  • Version v0.14.0

Additional context

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

@LittleFox94 LittleFox94 added the bug Something isn't working label Oct 27, 2023
@LittleFox94 LittleFox94 changed the title [BUG] [BUG] type checker gives false positive when WithTransform + Oct 27, 2023
@LittleFox94 LittleFox94 changed the title [BUG] type checker gives false positive when WithTransform + [BUG] type checker gives false positive for WithTransform + ContainElement Oct 27, 2023
@nunnatsa
Copy link
Owner

Thanks for letting me know, @LittleFox94!

@nunnatsa
Copy link
Owner

@LittleFox94 - would you like to review the fix? #116

@LittleFox94
Copy link
Author

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

@nunnatsa
Copy link
Owner

nunnatsa commented Nov 6, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants