From faba17a90f8efe64880e74d39340d70317cbfa1e Mon Sep 17 00:00:00 2001 From: doniacld Date: Sat, 30 Oct 2021 08:45:37 +0200 Subject: [PATCH] Fix package check in error-strings rule (#610) (#611) Co-authored-by: SalvadorC --- rule/error-strings.go | 3 +++ testdata/golint/error-strings.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/rule/error-strings.go b/rule/error-strings.go index ce16a83..f0739d9 100644 --- a/rule/error-strings.go +++ b/rule/error-strings.go @@ -105,6 +105,9 @@ func (w lintErrorStrings) match(expr *ast.CallExpr) bool { } // retrieve the package id, ok := sel.X.(*ast.Ident) + if !ok { + return false + } functions, ok := w.errorFunctions[id.Name] if !ok { return false diff --git a/testdata/golint/error-strings.go b/testdata/golint/error-strings.go index eb060b2..54dab8c 100644 --- a/testdata/golint/error-strings.go +++ b/testdata/golint/error-strings.go @@ -16,5 +16,9 @@ func g(x int) error { err = fmt.Errorf("Newlines are really fun\n") // MATCH /error strings should not be capitalized or end with punctuation or a newline/ err = errors.New(`too much stuff.`) // MATCH /error strings should not be capitalized or end with punctuation or a newline/ err = errors.New("This %d is too low", x) // MATCH /error strings should not be capitalized or end with punctuation or a newline/ + + // Non-regression test for issue #610 + d.stack.Push(from) + return err }