Affected GDScript Formatter:
0.20.1
Description:
The GDScript formatter currently has a critical indentation bug that renders functional scripts non-functional.
The faulty behavior seems to affect all block-level indentations. It can be reliably reproduced whenever a block-starting statement (e.g., an if-statement, for-loop, or any other statement requiring subsequent indentation) is immediately followed by an unindented comment.
When an unindented comment is present after the block-starting code statement, the formatter incorrectly unindents the execution block that follows, snapping it back to the same indentation level as the parent if or for statement.
Causing prior non-existent errors to scripts upon safe.
Steps to Reproduce / Minimal Example
Saved / Functional Script (Before Formatting / also expected result after formatting):
func _if_test() -> void:
if true:
#if false:
print("Execution Block for if statement - indented")
func _for_test() -> void:
for i in range(10):
#for i in range(5):
print(i)
Result after auto formatting (Broken Script):
func _if_test() -> void:
if true:
#if false:
print("Execution Block for if statement - indented")
func _for_test() -> void:
for i in range(10):
#for i in range(5):
print(i)
Impact & Use Cases
This behavior inevitably breaks the script's scope and leads to parser errors. Depending on the size of the script, this could cause significant overhead to manually track down and fix the broken indentations.
Regardless of whether these comments are considered "incorrectly" indented by strict style conventions, there are realistic and practical use cases for placing them there. For example, keeping alternative conditions or loop ranges right below the active one for quick debugging and testing.
Proposed Solution
Comments should have no influence on the indentation logic of the subsequent code. The linter should ignore comments when determining the required indentation level for the execution blocks that follow them.
Related issues
If read correctly, there seem´s to be something else involved, but it relates to issue #190
Metadata
Severity
- Script Breaking formatter behavior
GDScript Formatter Version
- 0.20.1
Godot Editor / Version
- Godot 4.7
IDE
- Godot 4.7 Editor | Script Editor
Affected GDScript Formatter:
0.20.1
Description:
The GDScript formatter currently has a critical indentation bug that renders functional scripts non-functional.
The faulty behavior seems to affect all block-level indentations. It can be reliably reproduced whenever a block-starting statement (e.g., an
if-statement,for-loop, or any other statement requiring subsequent indentation) is immediately followed by an unindented comment.When an unindented comment is present after the block-starting code statement, the formatter incorrectly unindents the execution block that follows, snapping it back to the same indentation level as the parent
iforforstatement.Causing prior non-existent errors to scripts upon safe.
Steps to Reproduce / Minimal Example
Saved / Functional Script (Before Formatting / also expected result after formatting):
Result after auto formatting (Broken Script):
Impact & Use Cases
This behavior inevitably breaks the script's scope and leads to parser errors. Depending on the size of the script, this could cause significant overhead to manually track down and fix the broken indentations.
Regardless of whether these comments are considered "incorrectly" indented by strict style conventions, there are realistic and practical use cases for placing them there. For example, keeping alternative conditions or loop ranges right below the active one for quick debugging and testing.
Proposed Solution
Comments should have no influence on the indentation logic of the subsequent code. The linter should ignore comments when determining the required indentation level for the execution blocks that follow them.
Related issues
If read correctly, there seem´s to be something else involved, but it relates to issue #190
Metadata
Severity
GDScript Formatter Version
Godot Editor / Version
IDE