Closed TomasMikula closed 8 years ago
It's a style warning that the code in the else block could be moved outside the if to decrease code nesting, like this:
noLint("""
def test(): Any = {
if(util.Random.nextBoolean) {
println("foo"); return 5; println("foo2");
}
println("foo3"); println("foo4");
}
}""")
I'll change the text of the warning, as it really doesn't explain this, and add this example to the test cases. Thanks for reporting!
Oh, OK, thanks!
The
UnnecessaryElseBranch
warning is issued whenWhat is the reasoning behind issuing this warning? When the
if
condition fails, theelse
branch is executed, so it doesn't seem unnecessary to me.This is one of the unit tests for
UnnecessaryElseBranch
:I don't see why the
else
branch would be unnecessary here.