1
0
mirror of https://github.com/mgechev/revive.git synced 2025-11-23 22:04:49 +02:00

fix error return rule to allow multiple error return values (#110)

* fix error return rule to allow multiple error return values

please check golint related updates here: golang/lint@8379672

When returning multiple values with an error,
lint checks if the error is the last return value.
But the implementation actually is checking for all return values
except for the last one, and throw the alert if it found an error.

There is a (edge) case where some function returning more than one error
is getting a false positive even when the last return value is an error.

This patch adds an early check, to see if the last return value is an error
and if so, it will pass silently.

* Fix return error

* add test changes
This commit is contained in:
Dian
2019-03-21 02:54:27 +08:00
committed by Minko Gechev
parent fbefad8558
commit 44eed7edb7
2 changed files with 13 additions and 0 deletions

View File

@@ -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] {