Skip to main content

Crate gdscript_fmt

Crate gdscript_fmt 

Source
Expand description

gdscript-fmt — the GDScript source formatter (Phase-6 Workstream 3).

A pure fn(source, &FmtConfig) -> String: no engine model, no filesystem, wasm32-safe. It re-emits the lexer/pre-pass token stream, normalizing block indentation (to the configured unit), trailing whitespace, and the final newline — every significant token (keywords, identifiers, literals — including multi-line strings, which are single tokens) is emitted verbatim, so meaning cannot change.

Safe by construction. In safe_mode (the default) the formatter (a) refuses to touch a file with syntax errors, and (b) re-lexes its own output and falls back to the original if the significant token sequence changed. So it never corrupts code, even input it doesn’t fully understand. The result is idempotent: format(format(x)) == format(x).

Intra-line spacing normalization and line-reflow (full gdformat parity, the Wadler/Prettier Doc-IR pretty-printer) are the documented next step — see TECH_DEBT.md. Today the formatter owns indentation + whitespace, which is the most common formatting need and the safest subset.

Structs§

FmtConfig
Formatter options. Defaults match the Godot convention (tabs) and keep the safety net on.

Functions§

format
Format source, returning the tidied text. In safe_mode (the default) this returns source unchanged rather than risk a meaning-changing edit (a syntax error in the input, or output whose significant tokens differ from the input’s).