lint: allow multiple error return values

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.

Fixes golang/lint#286

Change-Id: Ib3ad50ed127cdab6ac63e9d89c1c97f4a641f972
GitHub-Last-Rev: 9dd9de4fce5fccc846d010cc1c57720e33da85aa
GitHub-Pull-Request: golang/lint#387
Reviewed-on: https://go-review.googlesource.com/99295
Reviewed-by: Andrew Bonventre <andybons@golang.org>
diff --git a/lint.go b/lint.go
index f60106c..0305e8a 100644
--- a/lint.go
+++ b/lint.go
@@ -1310,6 +1310,9 @@
 		if len(ret) <= 1 {
 			return true
 		}
+		if isIdent(ret[len(ret)-1].Type, "error") {
+			return true
+		}
 		// An error return parameter should be the last parameter.
 		// Flag any error parameters found before the last.
 		for _, r := range ret[:len(ret)-1] {
diff --git a/testdata/error-return.go b/testdata/error-return.go
index 446a64c..520e8b2 100644
--- a/testdata/error-return.go
+++ b/testdata/error-return.go
@@ -41,3 +41,13 @@
 func m() (x int, err error, y int) { // MATCH /error should be the last type/
 	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
+}