gdtidy

Formatting

What gdtidy fmt changes, what it never touches, and how to keep a part of a file as written.

gdtidy fmt                   # format the whole project in place
gdtidy fmt player/ hud.gd    # only these files and folders
gdtidy fmt --check           # change nothing; list the files that would change
gdtidy fmt --diff            # change nothing; show the changes
gdtidy fmt -                 # format standard input to standard output

gdtidy fmt follows the official style guide. It keeps the line breaks you write and never wraps lines. Every result is parsed again and must have the same code as before, or the file is left alone and reported, so formatting can never change what a script does.

Keeping a part as written

# gdtidy: fmt-off
const TABLE = [
	[1,   0],
	[0,  10],
]
# gdtidy: fmt-on

Settings

Two choices where the guide and common practice disagree are settings:

  • Continuation indent for a line continued after foo(a, or a \: the guide uses two levels (continuation-indent = 2), but many projects use one. A bracket that ends its line, as in foo( followed by the arguments on their own lines, always indents its content by one level.
  • Spaces inside a one-line dictionary: the guide writes { "a": 1 }, but most projects write {"a": 1} (dict-brace-spaces = false).

Every change it makes

Everything here comes from the official style guide. gdtidy fmt changes layout and spelling only. Each result is parsed again and must have the same code and comments as the input; if it does not, the file is left alone and reported as unsafe, which is a gdtidy bug.

It never wraps or joins lines, reorders anything, or renames anything. Where the guide says nothing, such as the spaces before an inline comment, the author's choice is kept.

Lines and indentation

RuleExample
LF line endings, no byte order mark, no trailing whitespace, one final newline
One tab per block level; a file indented with spaces is converted
Inside a bracket that ends its line, one more level; the closing bracket goes backfoo(
→1,
)
A line continued after content on the opener's line, or after \, gets continuation-indent levels (2 by default)foo(a,
→→b)
Comment lines are indented like the code around them
Two blank lines around functions and classes, comments and annotations directly above included
At most two blank lines between other class members, one inside a function or brackets, none at the start of a block
One statement per line: a(); b() is split, a final ; removed (one-line lambdas are left alone)

Spacing

RuleBeforeAfter
One space around binary and assignment operators, and ->a+b, x=1, f()->inta + b, x = 1, f() -> int
One space after , and :, none beforef(a ,b), var a : intf(a, b), var a: int
:= kept togethervar a : = 1var a := 1
No space after a unary operator, except not- x-x
No space before a call's or subscript's bracket, nor inside bracketsf (x), a [0], [ 1 ]f(x), a[0], [1]
One space inside a one-line dictionary's braces (dict-brace-spaces){"a": 1}{ "a": 1 }
At least one space before an inline comment; more are keptx#cx #c

Node paths ($Node/Path, %Unique) are never touched.

Spelling

RuleBeforeAfter
Boolean operators in wordsa && !b || ca and not b or c
Double quotes, unless single quotes need fewer escapes'a', "say \"hi\"""a", 'say "hi"'
Lowercase hexadecimal digits0xFF0xff
Floats with both zeros.5, 1.0.5, 1.0
No parentheses around a whole one-line if, elif or while conditionif (a and b):if a and b:

Layout

RuleBeforeAfter
Enums one member per lineenum E {A, B}enum E {
→A,
→B,
}
A trailing comma in a multi-line array, dictionary or enum (trailing-commas)[
→1
]
[
→1,
]
No trailing comma in a one-line one[1, 2,][1, 2]

Differences with gdformat

gdformat 4.5gdtidy
Joins lines that fit, splits lines that do notKeeps the author's line breaks
enum E { A, B } on one lineOne member per line
Keeps &&, ||, !and, or, not
Keeps 0xFF, .5, 1.0xff, 0.5, 1.0
{"a": 1}{ "a": 1 }; gdtidy migrate sets dict-brace-spaces = false to keep gdformat's
Two spaces before an inline commentThe author's spacing
Writes CRLF on WindowsAlways LF