Skip to content

Continuation lines: Formatter struggles with wrapping if statements, and places only one indent instead of two in continuation lines. #224

@twilit-jack

Description

@twilit-jack

Consider this code:

func _test() -> void:
	var my_very_long_condition := true
	var my_other_very_long_condition := false

	if (my_very_long_condition
			or my_other_very_long_condition):
		pass

The formatter incorrectly changes the double indent into a single indent, and also, for some reason, adds a space before the ).

func _test() -> void:
	var my_very_long_condition := true
	var my_other_very_long_condition := false

	if (my_very_long_condition
		or my_other_very_long_condition ):
		pass

Furthermore, the formatter also doesn't place double indents in block style wrapping.

Example, expected:

func _test() -> void:
	var my_very_long_condition := true
	var my_other_very_long_condition := false

	if (
			my_very_long_condition
			or my_other_very_long_condition
	):
		pass

Formatted, incorrect:

func _test() -> void:
	var my_very_long_condition := true
	var my_other_very_long_condition := false

	if (
		my_very_long_condition
		or my_other_very_long_condition
	):
		pass

With chained methods, issue #217 first and foremost tells us that the methods just collapse, but if they didn't, I believe it also wouldn't be the correct 2 indent level.

Slightly modifying #217 , I give you this example that I believe is formatted correctly:

func _test() -> void:
	print("ABCDEF"
			.replace("A", "111111111111111111111111111111111111111111111111")
			.replace("B", "2")
			.replace("C", "3"))

But as dictated in #217 , this collapses:

func _test() -> void:
	print(
		"ABCDEF".replace("A", "111111111111111111111111111111111111111111111111").replace("B", "2").replace("C", "3"),
	)

But it's also worth mentioning that a block appears, which is yet again incorrectly formatted with one indent instead of two.


And another note, the formatter needs to know that arrays, dictionaries and enums should still use only one indent level:

var party = [
	"Godot",
	"Godette",
	"Steve",
]

var character_dict = {
	"Name": "Bob",
	"Age": 27,
	"Job": "Mechanic",
}

enum Tile {
	BRICK,
	FLOOR,
	SPIKE,
	TELEPORT,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions