Rubberduck
Rubberduck copied to clipboard
Auto-indent doesn't account for shortcut if with colon
Rubberduck version information
- Rubberduck version: 2.5.2.5906
- Operating System: Microsoft Windows NT 10.0.19044.0 x64
- Host Product: Microsoft Office x64
- Host Version: 16.0.14701.20262
- Host Executable: EXCEL.EXE;
Description
The indentation feature doesn't account for shortcut if statements using ":" and instead indents everything after it.
To Reproduce
Using auto-indent on the following:
Dim Test As Boolean
If Test Then
Debug.Print "TestTrue"
Else
Debug.Print "TestFalse"
End If
If Test Then: Debug.Print "ShortTestTrue"
Debug.Print "Shouldn't indent"
Debug.Print "Also shouldn't indent"
gets this:
Dim Test As Boolean
If Test Then
Debug.Print "TestTrue"
Else
Debug.Print "TestFalse"
End If
If Test Then: Debug.Print "ShortTestTrue"
Debug.Print "Shouldn't indent"
Debug.Print "Also shouldn't indent"
Expected behavior
The indentation should detect the colon after the "Then" as sign of a shortcut if-statement and don't add indentation to all following lines like this:
Dim Test As Boolean
If Test Then
Debug.Print "TestTrue"
Else
Debug.Print "TestFalse"
End If
If Test Then: Debug.Print "ShortTestTrue"
Debug.Print "Shouldn't indent"
Debug.Print "Also shouldn't indent"
Additional context
In a few other issues I've read to avoid duplicates I think I got that the indenter doesn't really know about the code's meaning itself and as such is queued for a complete rewrite anyway, but maybe this is easy enough to fix and/or helps finding kinks in the new implementation.
Log file with debug level logging enabled just before indenting: RubberduckLog.txt
I agree that the expected behavior is what should happen, however it should also be noted that the instruction separator token (:
) after the Then
keyword is both superfluous and confusing: it simply shouldn't be there at all.
Thanks, I didn't even know you could leave it out, just recently learned one-line-ifs are possible at all in VBA because I saw someone using it like this on SO and never questioned it ^^" If it's bad style maybe an inspection for this could also make sense then? : )