3. Linter (original) (raw)

gdlint is a static code analysis tool used to find potential problems in GDScript code.

For each provided file, this tool executes two phases in order:

  1. It parses the file thus checking if the code conforms to GDScript syntax
  2. It runs various predefined checks against the code

Linting with gdlint

To run a linter, just execute the gdlint command with some files as arguments e.g.:

$ gdlint misc/MarkovianPCG.gd

The command's exit code is 0 if both - parsing succeeded and checks were successful. Any lines in stdout mean that there were some problems found like e.g.:

misc/MarkovianPCG.gd:96: Error: Function argument name "aOrigin" is not valid (function-argument-name)
misc/MarkovianPCG.gd:96: Error: Function argument name "aPos" is not valid (function-argument-name)

Disabling checks on demand

In case of gdlint bugs or work-in-progress code it may be necessary to disable some checks. Each check can be disabled single time using gdlint:ignore comment:

# gdlint:ignore = function-name , function-argument-name
func SomeWrongName(someArg):
    assert(someArg > 0)

In case some checks must be disabled in larger file area, the gdlint: disable (with optional gdlint: enable) comment may be used:

# gdlint: disable=function-name
func SomeWrongName():
    pass
# gdlint: enable=function-name

Tweaking default check settings

To tweak the default check settings, you can dump the default config to a file:

$ gdlint -d
$ cat gdlintrc
class-load-variable-name: (([A-Z][a-z0-9]*)+|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
class-name: ([A-Z][a-z0-9]*)+
class-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
constant-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*'
disable: []
enum-element-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*'
enum-name: ([A-Z][a-z0-9]*)+
function-argument-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
function-arguments-number: 10
function-preload-variable-name: ([A-Z][a-z0-9]*)+
function-name: (_on_([A-Z][a-z0-9]*)+(_[a-z0-9]+)*|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
function-variable-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
load-constant-name: (([A-Z][a-z0-9]*)+|[A-Z][A-Z0-9]*(_[A-Z0-9]+)*)
loop-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
signal-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
sub-class-name: _?([A-Z][a-z0-9]*)+

Once the dump is performed, you can modify the gdlintrc file and optionally rename it to .gdlintrc. From now on, linter will use this config file to override the default config.

Checks

The linter checks are divided into categories:

Name checks

Basic checks

Class checks

Design checks

Format checks

Misc checks