diff --git a/fixtures/golint/error-return.go b/fixtures/golint/error-return.go index b6a0eda..783ab74 100644 --- a/fixtures/golint/error-return.go +++ b/fixtures/golint/error-return.go @@ -41,3 +41,13 @@ func l() (int, error, int) { // MATCH /error should be the last type when return func m() (x int, err error, y int) { // MATCH /error should be the last type when returning multiple items/ return 0, nil, 0 } + +// Check for multiple error returns but with errors at the end. +func n() (int, error, error) { // ok + return 0, nil, nil +} + +// Check for multiple error returns mixed in order, but keeping one error at last position. +func o() (int, error, int, error) { // ok + return 0, nil, 0, nil +} diff --git a/rule/error-return.go b/rule/error-return.go index df847b3..737d8c6 100644 --- a/rule/error-return.go +++ b/rule/error-return.go @@ -47,6 +47,9 @@ func (w lintErrorReturn) Visit(n ast.Node) ast.Visitor { if len(ret) <= 1 { return w } + if isIdent(ret[len(ret)-1].Type, "error") { + return nil + } // An error return parameter should be the last parameter. // Flag any error parameters found before the last. for _, r := range ret[:len(ret)-1] {