Package: gdtoolkit
GDScript ToolkitThis project provides a set of tools for daily work withGDScript. At the moment it provides:A parser that produces a parse tree for debugging and educational purposes.A linter that performs a static analysis according to some predefined configuration.A formatter that formats the code according to some predefined rules.A code metrics calculator which calculates cyclomatic complexity of functions and classes.InstallationTo install this project you needpython3andpip.
Regardless of the target version, installation is done bypip3command and for stable releases, it downloads the package from PyPI.Godot 4pip3 install "gdtoolkit==4.*"Godot 3pip3 install "gdtoolkit==3.*"master(latest)Latest version (potentially unstable) can be installed directly from git:pip3 install git+https://github.com/Scony/godot-gdscript-toolkit.gitLinting with gdlint(more)To run a linter you need to executegdlintcommand like:$ gdlint misc/MarkovianPCG.gdWhich outputs messages like: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)Formatting with gdformat(more)Formatting may lead to data loss, so it's highly recommended to use it along with Version Control System (VCS) e.g.gitTo run a formatter you need to executegdformaton the file you want to format. So, given atest.gdfile: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 executegdformat test.gdcommand, thetest.gdfile 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')Parsing with gdparse(more)To run a parser you need to execute thegdparsecommand like:gdparse tests/valid-gd-scripts/recursive_tool.gd -pThe parser outputs a tree that represents your code's structure:start
  class_def
    X
    class_body
      tool_stmt
      signal_stmt	sss
  class_def
    Y
    class_body
      tool_stmt
      signal_stmt	sss
  tool_stmtCalculating cyclomatic complexity with gdradonTo run cyclomatic complexity calculator you need to execute thegdradoncommand like:gdradon cc tests/formatter/input-output-pairs/simple-function-statements.in.gd tests/gd2py/input-output-pairs/The command outputs calculated metrics just likeRadon cc commanddoes for Python code:tests/formatter/input-output-pairs/simple-function-statements.in.gd
    C 1:0 X - A (2)
    F 2:1 foo - A (1)
tests/gd2py/input-output-pairs/class-level-statements.in.gd
    F 22:0 foo - A (1)
    F 24:0 bar - A (1)
    C 18:0 C - A (1)
tests/gd2py/input-output-pairs/func-level-statements.in.gd
    F 1:0 foo - B (8)Using gdtoolkit's GitHub actionIn order to setup a simple action with gdtoolkit's static checks, the base action from this repo can be used:name: Static checks

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  static-checks:
    name: 'Static checks'
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: Scony/godot-gdscript-toolkit@master
    - run: gdformat --check source/
    - run: gdlint source/See the discussion inhttps://github.com/Scony/godot-gdscript-toolkit/issues/239for more details.Development(more)Everyone is free to fix bugs or introduce new features. For that, however, please refer to existing issue or create one before starting implementation.