bools

Imports

Imports #

"go/ast"
"go/token"
"go/types"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"

Constants & Variables

Analyzer var #

var Analyzer = *ast.UnaryExpr

Doc const #

const Doc = "check for common mistakes involving boolean operators"

and var #

var and = boolOp{...}

or var #

var or = boolOp{...}

Structs

boolOp struct #

type boolOp struct {
name string
tok token.Token
badEq token.Token
}

Functions

checkRedundant method #

checkRedundant checks for expressions of the form e && e e || e Exprs must contain only side effect free expressions.

func (op boolOp) checkRedundant(pass *analysis.Pass, exprs []ast.Expr)

checkSuspect method #

checkSuspect checks for expressions of the form x != c1 || x != c2 x == c1 && x == c2 where c1 and c2 are constant expressions. If c1 and c2 are the same then it's redundant; if c1 and c2 are different then it's always true or always false. Exprs must contain only side effect free expressions.

func (op boolOp) checkSuspect(pass *analysis.Pass, exprs []ast.Expr)

commutativeSets method #

commutativeSets returns all side effect free sets of expressions in e that are connected by op. For example, given 'a || b || f() || c || d' with the or op, commutativeSets returns {{b, a}, {d, c}}. commutativeSets adds any expanded BinaryExprs to seen.

func (op boolOp) commutativeSets(info *types.Info, e *ast.BinaryExpr, seen map[*ast.BinaryExpr]bool) [][]ast.Expr

run function #

func run(pass *analysis.Pass) (interface{}, error)

split method #

split returns a slice of all subexpressions in e that are connected by op. For example, given 'a || (b || c) || d' with the or op, split returns []{d, c, b, a}. seen[e] is already true; any newly processed exprs are added to seen.

func (op boolOp) split(e ast.Expr, seen map[*ast.BinaryExpr]bool) (exprs []ast.Expr)

Generated with Arrow