-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package golinters | ||
|
||
import ( | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
"github.com/gostaticanalysis/nilerr" | ||
"golang.org/x/tools/go/analysis" | ||
) | ||
|
||
func NewNilErr() *goanalysis.Linter { | ||
a := nilerr.Analyzer | ||
return goanalysis.NewLinter( | ||
a.Name, | ||
"Finds the code that returns nil even if it checks that the error is not nil.", | ||
[]*analysis.Analyzer{a}, | ||
nil, | ||
).WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//args: -Enilerr | ||
package testdata | ||
|
||
func nilErr1() error { | ||
err := nilErrDo() | ||
if err == nil { | ||
return err // ERROR `error is nil \(line 5\) but it returns error` | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func nilErr2() error { | ||
err := nilErrDo() | ||
if err == nil { | ||
return err // ERROR `error is nil \(line 14\) but it returns error` | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func nilErr3() error { | ||
err := nilErrDo() | ||
if err != nil { | ||
return nil // ERROR `error is not nil \(line 23\) but it returns nil` | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func nilErrDo() error { | ||
return nil | ||
} |