diff --git a/analyzer_test.go b/analyzer_test.go index b0bb0ec..dff0c2d 100644 --- a/analyzer_test.go +++ b/analyzer_test.go @@ -97,6 +97,10 @@ func TestAllUseCases(t *testing.T) { testName: "HaveOccurred matcher tests", testData: "a/haveoccurred", }, + { + testName: "nil error-func variable", + testData: "a/issue-171", + }, } { t.Run(tc.testName, func(tt *testing.T) { analysistest.Run(tt, analysistest.TestData(), ginkgolinter.NewAnalyzer(), tc.testData) diff --git a/internal/rules/errorequalnilrule.go b/internal/rules/errorequalnilrule.go index 7aaf763..81932cc 100644 --- a/internal/rules/errorequalnilrule.go +++ b/internal/rules/errorequalnilrule.go @@ -12,8 +12,15 @@ import ( type ErrorEqualNilRule struct{} func (ErrorEqualNilRule) isApplied(gexp *expression.GomegaExpression, config types.Config) bool { - return !bool(config.SuppressErr) && - gexp.ActualArgTypeIs(actual.ErrorTypeArgType) && + if config.SuppressErr { + return false + } + + if !gexp.IsAsync() && gexp.ActualArgTypeIs(actual.FuncSigArgType) { + return false + } + + return gexp.ActualArgTypeIs(actual.ErrorTypeArgType) && gexp.MatcherTypeIs(matcher.BeNilMatcherType|matcher.EqualNilMatcherType) } diff --git a/testdata/src/a/issue-171/issue171.go b/testdata/src/a/issue-171/issue171.go new file mode 100644 index 0000000..dd6a26f --- /dev/null +++ b/testdata/src/a/issue-171/issue171.go @@ -0,0 +1,16 @@ +package issue_171 + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +var _ = Describe("test if issue 171 was solved", func() { + It("should not trigger warning for nil function vars", func() { + f := func(string) error { return nil } + + f = nil + + Expect(f).To(BeNil()) + }) +})