1
0
mirror of https://github.com/mgechev/revive.git synced 2025-01-10 03:17:11 +02:00
revive/fixtures/superfluous-else.go
chavacava cbe45ffc79 Adds rule superfluous-else (an extension of indent-error-flow) (#13)
* Adds rule superfluous-else (an extension of indent-error-flow)

* Fix superfluous-else rule struct namming.

* Adds superfuous-else rule to the rules table
2018-06-08 07:06:29 -07:00

74 lines
1.2 KiB
Go

// Test of return+else warning.
// Package pkg ...
package pkg
import (
"fmt"
"log"
)
func h(f func() bool) string {
for {
if ok := f(); ok {
a := 1
continue
} else { // MATCH /if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)/
return "it's NOT okay!"
}
}
}
func i(f func() bool) string {
for {
if f() {
a := 1
continue
} else { // MATCH /if block ends with a continue statement, so drop this else and outdent its block/
log.Printf("non-positive")
}
}
return "ok"
}
func j(f func() bool) string {
for {
if f() {
break
} else { // MATCH /if block ends with a break statement, so drop this else and outdent its block/
log.Printf("non-positive")
}
}
return "ok"
}
func k() {
var a = 10
/* do loop execution */
LOOP:
for a < 20 {
if a == 15 {
a = a + 1
goto LOOP
} else { // MATCH /if block ends with a goto statement, so drop this else and outdent its block/
fmt.Printf("value of a: %d\n", a)
a++
}
}
}
func j(f func() bool) string {
for {
if f() {
a := 1
fallthrough
} else {
log.Printf("non-positive")
}
}
return "ok"
}