Skip to main content

Independent set of tools for working with GDScript - parser, linter and formatter

Project description

GDScript Toolkit

License: MIT Code style: black

This project provides a set of tools for daily work with GDScript. 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.

Installation

To install this project you need python3 and pip.

Use this command to install gdtoolkit for Godot 3 from PyPI repository:

pip3 install 'gdtoolkit==3.*'

Alternatively, you can install latest (potentially unstable) version directly from git:

pip3 install git+https://github.com/Scony/godot-gdscript-toolkit.git

Linting with gdlint (more)

To run a linter you need to execute gdlint command like:

$ gdlint misc/MarkovianPCG.gd

Which 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. git

To run a formatter you need to execute gdformat on the file you want to format. So, 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 execute gdformat test.gd command, 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')

Parsing with gdparse (more)

To run a parser you need to execute the gdparse command like:

gdparse tests/valid-gd-scripts/recursive_tool.gd -p

The 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_stmt

Calculating cyclomatic complexity with gdradon

To run cyclomatic complexity calculator you need to execute the gdradon command like:

gdradon cc tests/formatter/input-output-pairs/simple-function-statements.in.gd tests/gd2py/input-output-pairs/

The command outputs calculated metrics just like Radon cc command does 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)

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gdtoolkit-3.6.0.tar.gz (38.9 kB view details)

Uploaded Source

Built Distribution

gdtoolkit-3.6.0-py3-none-any.whl (50.9 kB view details)

Uploaded Python 3

File details

Details for the file gdtoolkit-3.6.0.tar.gz.

File metadata

  • Download URL: gdtoolkit-3.6.0.tar.gz
  • Upload date:
  • Size: 38.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for gdtoolkit-3.6.0.tar.gz
Algorithm Hash digest
SHA256 2826e001b286b22e113637d2a23da8380b3be36820f01f3c48ece0f644ec7b48
MD5 e9c83a7447c267c8c6382e851fbac110
BLAKE2b-256 b6690f1c14e30b31d97a0519bb3139638524ad745cec98a06468965f82cb4b6e

See more details on using hashes here.

File details

Details for the file gdtoolkit-3.6.0-py3-none-any.whl.

File metadata

  • Download URL: gdtoolkit-3.6.0-py3-none-any.whl
  • Upload date:
  • Size: 50.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for gdtoolkit-3.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 316a1305a62de61d61ddda99cc4d2118dc08e3e5c3323cf82db099fe8df1cae3
MD5 7d9c09d311cd1b6c95f470ad787a18ef
BLAKE2b-256 f282c851bedacf83ab0b5424a5b38bb7fd55ad4cce8369d67bb122e56e034928

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page