-
-
Notifications
You must be signed in to change notification settings - Fork 72
4. Formatter
gdformat
is an uncompromising GDScript code formatter. The only configurable thing is
max line length allowed. The rest will be taken care of by gdformat in a one,
consistent way.
Formatting may lead to data loss, so it's highly recommended to use it along with Version Control System (VCS) e.g. git
gdformat
is the uncompromising GDScript code formatter. The only configurable thing is max line length allowed (--line-length
). The rest will be taken care of by gdformat
in a one, consistent way.
To run a formatter you need to perform installation first. Once done, given a test.gd
file:
class X:
var x=[1,2,{'a':1}]
var y=[1,2,3,] # trailing comma
func foo(a:int,b,c=[1,2,3]):
if a in c and \
b > 100:
print('foo')
func bar():
print('bar')
when you run gdformat test.gd
, the test.gd
file will be reformatted as follows:
class X:
var x = [1, 2, {'a': 1}]
var y = [
1,
2,
3,
] # trailing comma
func foo(a: int, b, c = [1, 2, 3]):
if a in c and b > 100:
print('foo')
func bar():
print('bar')
If the program formats your files successfully, it will return the exit code 0
. Non-zero code will be returned otherwise.
To skip certain directories, you can invoke:
gdformat --dump-default-config
to generate gdformatrc
file. This file can then be modified to instruct formatter to skip certain directories:
excluded_directories: !!set
.git: null
addons: null
after next gdformat
execution it will pick the gdformatrc
file if it exists and it will act accordingly.