1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-24 08:32:22 +02:00
revive/testdata/if-return.go
2021-06-29 13:04:51 -07:00

102 lines
1.5 KiB
Go

// Test of redundant if err != nil
// Package pkg ...
package pkg
func f() error {
if err := f(); err != nil {
g()
return err
}
return nil
}
func g() error {
if err := f(); err != nil { // MATCH /redundant if ...; err != nil check, just return error instead./
return err
}
return nil
}
func h() error {
if err, x := f(), 1; err != nil {
return err
}
return nil
}
func i() error {
a := 1
if err := f(); err != nil {
a++
return err
}
return nil
}
func j() error {
var a error
if err := f(); err != nil {
return err
}
return a
}
func k() error {
if err := f(); err != nil {
// TODO: handle error better
return err
}
return nil
}
func l() (interface{}, error) {
if err := f(); err != nil {
return nil, err
}
if err := f(); err != nil {
return nil, err
}
if err := f(); err != nil {
return nil, err
}
// Phew, it worked
return nil
}
func m() error {
if err := f(); err != nil {
return err
}
if err := f(); err != nil {
return err
}
if err := f(); err != nil {
return err
}
// Phew, it worked again.
return nil
}
func multi() error {
a := 0
var err error
// unreachable code after return statements is intentional to check that it
// doesn't confuse the linter.
if true {
a++
if err := f(); err != nil { // MATCH /redundant if ...; err != nil check, just return error instead./
return err
}
return nil
a++
} else {
a++
if err = f(); err != nil { // MATCH /redundant if ...; err != nil check, just return error instead./
return err
}
return nil
a++
}
}