Skip to content

--reorder-code inserts a space before subscript brackets (foo()[i]foo() [i]) and expands empty dict {} to { }, diverging from the official GDScript style guide #259

Description

@minami110

Tested on gdscript-formatter 0.21.0 (Pre-release 0.21.0-beta, published 2026-07-12), Linux x86_64. Upstream main checked up to 248fa13b (2026-07-12 09:20 UTC) — no fix commit found.

The empty-dict part ({}{ }) looks like a regression of #152 "Formatter is inserting a space inside of empty dictionary literals" (closed).

Impact (style-guide deviation, non-breaking)

The GDScript style guide — Whitespace section shows array[3] and dict["key"] with no space between the closing )/identifier/}/] and the following [. Formatter output diverges from that.

Trigger

Any subscript on the result of a call or cast — foo()[i], (x as Dictionary)[key], arr.split(".")[0]. Also any empty dict literal {}.

Repro

Input (bug.gd):

func demo() -> void:
	var d: Dictionary = {}
	var v: Variant = (d as Dictionary)["key"]
	print(v)

Command:

gdscript-formatter --stdout --reorder-code bug.gd

Actual output

func demo() -> void:
	var d: Dictionary = { }
	var v: Variant = (d as Dictionary) ["key"]
	print(v)

Expected (per official style guide)

func demo() -> void:
	var d: Dictionary = {}
	var v: Variant = (d as Dictionary)["key"]
	print(v)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions