-
Notifications
You must be signed in to change notification settings - Fork 490
Add a check for boolean expressions containing pointless/overriding connectives #45
Comments
It is indeed a better fit for lint than vet. I'm not sure about your first four (comparing against true/false). It's true that they are equivalent, but code can carry semantic emphasis by doing that, so I'm wary of flagging them as wrong. The remainder, now that I think about it, might match vet better. Though they are not incorrect code, they may be accidentally hiding code, and flagging them there probably makes sense in the same way that flagging unreachable code makes sense. I wonder what Rob thinks about that idea. |
Do you have an example handy? Flipping through instances from the corpus, comparing against true/false appears to be a habit of the developer, rather than being reserved for emphasis.
That was the theory I held when I wrote it as a vet check, but it didn't survive first contact. I did some sampling, and I did not find any flagged code that was clearly buggy. I found lots of code that I didn't understand -- and which thus might have been buggy -- but nothing obviously incorrect. I'd prefer to be wrong about this though, so feel free to push on it. :) |
On 28 June 2014 01:53, Josh Bleecher Snyder notifications@github.com wrote:
I don't have an example handy, but it reminds me of test code for
If it empirically doesn't find any bad code, or very little bad code, |
Sounds right. Dropped! Thanks for the helpful discussion. |
m |
I originally prepared a
go vet
check for this, but came to the conclusion that it was a better fit forgo lint
. I'm opening this issue as a place to stash the idea + tested go vet code until such time as I (or someone else) adapts it.Running this check over a recent corpus of public code caught this distribution of ugliness:
Test cases:
Excerpted
vet
check:Note that most of these can be fixed with simple
gofmt -r
invocations.The text was updated successfully, but these errors were encountered: