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

Fix package check in error-strings rule (#610) #611

Merged
merged 2 commits into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions rule/error-strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions testdata/golint/error-strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}