go-tools icon indicating copy to clipboard operation
go-tools copied to clipboard

simple: flag superfluous boolean variable declarations in if statements

Open NiloCK opened this issue 2 years ago • 1 comments

A potential new check:

Consider

if testValue := someFunc(); testValue {
  // do some stuff which doesn't use testValue
}

testValue passes the compiler's check for an unused variable, but is it really used? In my view, the code

if someFunc() {
  // do some stuff which doesn't use testValue
}

is unambiguously better.

NiloCK avatar Jan 04 '23 14:01 NiloCK

A quick note that if testValue is used in the block it can be statically replaced with a true (or false, depending).

dgryski avatar Jan 04 '23 18:01 dgryski