Skip to content

Commit

Permalink
stylecheck: avoid flagging error strings that begin with a function call
Browse files Browse the repository at this point in the history
Closes gh-452

(cherry picked from commit d9d28f5)
  • Loading branch information
dominikh committed Oct 10, 2020
1 parent 33cf363 commit a4a005d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stylecheck/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ func CheckErrorStrings(pass *analysis.Pass) (interface{}, error) {
}
}

if strings.ContainsRune(word, '(') {
// Might be a function call
continue instrLoop
}
word = strings.TrimRightFunc(word, func(r rune) bool { return unicode.IsPunct(r) })
if objNames[fn.Package()][word] {
// Word is probably the name of a function or type in this package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ func fn() {
errors.New("SomeFunc is okay")
errors.New("URL is okay, but the period is not.") // want `error strings should not end with punctuation or a newline`
errors.New("T must not be nil")
errors.New("Foo() failed")
errors.New("Foo(bar) failed")
errors.New("Foo(bar, baz) failed")
}

func Write() {
Expand Down

0 comments on commit a4a005d

Please sign in to comment.