mirror of
https://github.com/mgechev/revive.git
synced 2025-05-15 21:56:38 +02:00
* rule: tests for Configure with named options; fix errors * rule: refactor and add tests for ifelse rules * rule: allow lowercased and kebab-cased options * test: update integration tests with lowercased params * docs: update rules descriptions * rule: simplify Configure implementation with one option * gofmt and fix lint * review: add isRuleOption, update grammar in doc, simplify regex Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> --------- Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
// Test of return+else warning.
|
|
|
|
// Package pkg ...
|
|
package pkg
|
|
|
|
import "log"
|
|
|
|
func f(x int) bool {
|
|
if x > 0 {
|
|
return true
|
|
} else { // MATCH /if block ends with a return statement, so drop this else and outdent its block/
|
|
log.Printf("non-positive x: %d", x)
|
|
}
|
|
return false
|
|
}
|
|
|
|
func g(f func() bool) string {
|
|
if ok := f(); ok {
|
|
return "it's okay"
|
|
} else { // MATCH /if block ends with a return 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 h(f func() bool, x int) string {
|
|
if err == author.ErrCourseNotFound {
|
|
return
|
|
} else if err == author.ErrCourseAccess {
|
|
// side effect
|
|
} else if err == author.AnotherError {
|
|
return "okay"
|
|
} else {
|
|
if ok := f(); ok {
|
|
return "it's okay"
|
|
} else { // MATCH /if block ends with a return 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() string {
|
|
if err == author.ErrCourseNotFound {
|
|
return "not found"
|
|
} else if err == author.AnotherError {
|
|
return "something else"
|
|
} else { // MATCH /if block ends with a return statement, so drop this else and outdent its block/
|
|
return "okay"
|
|
}
|
|
}
|