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] False Positive for HaveOccurred() matcher with .Error() #173

Closed
maboehm opened this issue Nov 11, 2024 · 2 comments · Fixed by #175
Closed

[BUG] False Positive for HaveOccurred() matcher with .Error() #173

maboehm opened this issue Nov 11, 2024 · 2 comments · Fixed by #175
Assignees
Labels
bug Something isn't working

Comments

@maboehm
Copy link

maboehm commented Nov 11, 2024

Describe the bug
When using the .Error() chaining method on an expectation, the linter incorrectly finds an issue, even though this exact pattern is shown in the official documentation as

Ω(MultipleReturnValuesFunc()).Error().ShouldNot(HaveOccurred())

See https://onsi.github.io/gomega/#handling-errors

To Reproduce

package main_test

import (
	"testing"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
)

func TestE2E(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "demo")
}

func foo() (bool, error) {
	return false, nil
}

var _ = Describe("demo", func() {
	It("should work", func() {
		Expect(foo()).Error().NotTo(HaveOccurred())
	})
})

Returns

main_test.go:21:3: ginkgo-linter: asserting a non-error type with HaveOccurred matcher

Expected behavior
Get no warning.

Environment:

  • OS: macos
  • Version latest (0.18.1)
  • go: 1.22.9

Additional context
We first observed this when bumping golangci-lint, which bumped this linter from 0.16.0 to 0.18.0

@nunnatsa
Copy link
Owner

Thanks @maboehm - I'll take a look.

@nunnatsa
Copy link
Owner

nunnatsa commented Nov 11, 2024

Just released v0.18.2 with a fix to this bug.

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