Go

Go

Made by DeepSource

Found redundant control flow SCC-S1023

Anti-pattern
Major
Autofix

Omit redundant control flow in your Go code.

Following cases should be considered to omit redundant control flow:

  • Functions that have no return value do not need a return statement as the final statement of the function.
  • The switch statement in Go does not have automatic fallthrough, unlike languages like C. It is unnecessary to have a break statement as the final statement in a case block.

Bad practice

func foo() {
    fmt.Println("foo")
    return
}
switch 1 {
    case 1:
        fmt.Println(case one)
        break
    case 2:
        fmt.Println(case two)
}

Recommended

func foo() {
    fmt.Println("foo")
}
switch 1 {
    case 1:
        fmt.Println(case one)
    case 2:
        fmt.Println(case two)
}