-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inspection for literal boolean conditions #2218
Comments
Might also be worth checking any literal that will be cast to Boolean literal: If "TRUE" Then
'This runs
Beep
End If
If "FALSE" Then
'Unreachable
Beep
End If
If "1E23" Then
'This runs
Beep
End If
If 10 And 11 Then
'This runs
Beep
End If
If 42 Then
'This runs
Beep
End If
If -42 Then
'This runs
Beep
End If
If 0 Then
'This is unreachable code
Beep
End If
|
The good news is that there's already a The problem might be with performance: literals are [literally] everywhere, and walking the parse trees is expensive. OTOH we won't know how bad it is until we try it.
Comments are never parsed as code, Rubberduck has no way of knowing that the commented-out condition is actually dead code. I think it's best to treat comments as what they are: not code. Besides, code-in-comments should be punishable by ... by Rubberduck forcing your solution onto source control and automatically removing them all. Would be nice to be able to tell code from gibberish in comments though. |
We need to be careful, as Sub foo()
Dim ignoreResults
ignoreResults = True
Dim rng As Range
Set rng = Range("A1:C5")
'Execute the first Case that evaluates to true
Select Case True
Case ignoreResults
Beep
Case Not rng Is Nothing
Beep
Case Else
Beep
End Select
End Sub |
I wouldn't trip a warning on |
Exactly |
So, we have an inspection that says:
What's the quick-fix? Do we suggest implementing the condition as a precompiler directive? |
At the very least I'd implement a constant and give the user the option of its name and scope. |
We've all done it... You're debugging and you want to skip or enter an
If
block.... Only you forget to reinstate the condition, so next time the code runs in PROD, the nukes either fail to launch, or they're all launched at once....Rubberduck should have an inspection for code like:
Quickfixes might need to be aware of comments that have preserved the "real" condition:
The text was updated successfully, but these errors were encountered: