Avoid unnecessary if statements

Go pattern

If statements that always evaluate to true or false are redundant and should be removed.


Apply with the Grit CLI
grit apply no_unnecessary_conditionals

Warning for INCORRECT comparison if (True)

BEFORE
package main

import "fmt"

func mainFunc() {
    fmt.Println("hello world")
    var y = "hello";

    if (true) {
        fmt.Println("never")
    }
}
AFTER
package main

import "fmt"

func mainFunc() {
    fmt.Println("hello world")
    var y = "hello";

    fmt.Println("never")
}

Warning for INCORRECT comparison if (False)

BEFORE
package main

import "fmt"

func mainFunc() {
    fmt.Println("hello world")
    var y = "hello";

    if (false) {
        fmt.Println("never")
    }
}
AFTER
package main

import "fmt"

func mainFunc() {
    fmt.Println("hello world")
    var y = "hello";

}