godot-gdscript-toolkit icon indicating copy to clipboard operation
godot-gdscript-toolkit copied to clipboard

Weird GDFormat style guidelines

Open tavurth opened this issue 1 year ago • 4 comments
trafficstars

Regarding the provided code examples, I share the opinion that the current GDFormat output could be improved to align better with popular formatting conventions:

my_array.append({
    # no-wrap
    "some": "a",
    "thing": "b",
    "is_weird": "something very long",
})

The GDFormat currently formats it as:

(
    my_array
    . append(
        {
            # no-wrap
            "some": "a",
            "thing": "b",
            "is_weird": "something very long",
        }
    )
)

The extra newline between append( and {, as well as the space between the dot and the method name, make the code a bit harder to read and deviate from common conventions.

  1. Regarding the newline between append( and {:
  1. Regarding the space between the dot and the method name:

And finally the Godot source code itself.

tavurth avatar Mar 21 '24 11:03 tavurth

I should note the example formatted differently I guess:

Python

my_array.append(
    {
        # no-wrap
        "some": "a",
        "thing": "b",
        "is_weird": "something very long",
    }
)

Java

my_array.append({
            "some": "a",
            "thing": "b",
            "is_weird": "something very long",
        })

C++

my_array.append({
  "some": "a",
  "thing": "b",
  "is_weird": "something very long",
})

Javascript

my_array.append({
    "some": "a",
    "thing": "b",
    "is_weird": "something very long",
})

tavurth avatar Mar 21 '24 11:03 tavurth

I think it was discussed already in some issue but I couldn't find it. Anyway - I'd love to add support for such compact conventions but the thing is that it would take a lot of time to implement. Currently, the formatter operates in 2 modes (or strategies if you will) and chooses the one that fits better at a given point:

  1. "format everything to single line" - which does exactly what it says
  2. "format to multiple lines" - which formats to multiple lines and potentially falls back to 1) at deeper levels.

The correct approach to implement compact multiline formatting would be to add a new, 3rd strategy and use it in cases where it fits better. Such a strategy would require implementing custom formatting rules for all parse tree nodes which (assuming full test coverage) would require tons of man-hours to implement.

Therefore- realistically speaking - this feature probably won't ever be implemented although it would be a cool thing to have I agree.

Scony avatar Mar 21 '24 21:03 Scony

I would just like to mention that this issue is displaying itself quite clearly in the following bit of code I have. It's an array of integers, which I would like to format into groups of 6 because of texture sheet reasons, but instead I get this 32-line long monstrosity.

var head_offsets: PackedInt32Array = [
	5,
	5,
	5,
	5,
	5,
	5,
	0,
	0,
	0,
	0,
	0,
	4,
	0,
	-1,
	4,
	0,
	-1,
	-1,
	1,
	1,
	1,
	1,
	0,
	0,
	0,
	-2,
	0,
	0,
	0,
	-2,
]

IntangibleMatter avatar Aug 17 '24 12:08 IntangibleMatter

I would just like to mention that this issue is displaying itself quite clearly in the following bit of code I have. It's an array of integers, which I would like to format into groups of 6 because of texture sheet reasons, but instead I get this 32-line long monstrosity.

var head_offsets: PackedInt32Array = [
	5,
	5,
	5,
	5,
	5,
	5,
	0,
	0,
	0,
	0,
	0,
	4,
	0,
	-1,
	4,
	0,
	-1,
	-1,
	1,
	1,
	1,
	1,
	0,
	0,
	0,
	-2,
	0,
	0,
	0,
	-2,
]

as for the above - it will be possible to skip formatting of such statement once https://github.com/Scony/godot-gdscript-toolkit/issues/52 is implemented.

Scony avatar Aug 18 '24 13:08 Scony