Skip to content

--reorder-code splits x in [ ... ] into x / in [ ... ], producing a parse error #257

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.

Impact (critical — parse error)

Places in at statement top. GDScript rejects this — running the formatted file yields Parse Error: Expected statement, found "in" instead and the whole script fails to load. Consumers that reference the class (via preload / class_name) then cascade into "Identifier X not declared" errors.

Trigger

return <expr> in [ ... ] where the list already spans multiple lines. Line-length wrapping decides to break before in and drops the operator + [ to the next line.

Repro

Input (bug.gd):

static func is_known_effect_kind(name: StringName) -> bool:
	return name in [
		&"harvest_multiplier", &"energy_bonus", &"free_return_trip",
		&"all_weather_roads", &"fertilizer_next_day_bloom", &"bloom_all_nodes",
		&"bloom_bonus_boost", &"restore_hunger", &"restore_sleepiness",
	]

Command:

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

Actual output

static func is_known_effect_kind(name: StringName) -> bool:
	return name
	in [
		&"harvest_multiplier",
		&"energy_bonus",
		&"free_return_trip",
		&"all_weather_roads",
		&"fertilizer_next_day_bloom",
		&"bloom_all_nodes",
		&"bloom_bonus_boost",
		&"restore_hunger",
		&"restore_sleepiness",
	]

Expected

Keep return name in [ on one line, wrap only the list elements. Never place in at statement top.

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