1
0
mirror of https://github.com/golang/go synced 2024-10-01 08:28:43 -06:00
Commit Graph

1 Commits

Author SHA1 Message Date
Josh Bleecher Snyder
7da5f193b7 go.tools/cmd/vet: detect stupid boolean conditions
This CL introduces two vet checks. Statistics and code below are from a recent 50mb corpus of public code.

1. Check for redundant conjunctions and disjunctions. This check caught 26 instances, of which 20 were clearly copy/paste bugs and 6 appeared to be mere duplication. A typical example:

if xResolution < 0 || xResolution < 0 {
        panic("SetSize(): width < 0 || height < 0")
}

2. Check for expressions of the form 'x != c1 || x != c2' or 'x == c1 && x == c2', with c1 and c2 constant expressions. This check caught 16 instances, of which all were bugs. A typical example:

if rf.uri.Scheme != "http" || rf.uri.Scheme != "ftp" {
        rf.uri.Scheme = "file"
}

Fixes golang/go#7622.

LGTM=rsc, r
R=golang-codereviews, jscrockett01, r, gri, rsc
CC=golang-codereviews
https://golang.org/cl/98120043
2014-07-02 10:39:57 -07:00