From 8df572340a6bc4a7ced7437520f70a1dd0236072 Mon Sep 17 00:00:00 2001 From: Pawel Lampe Date: Mon, 19 Dec 2022 23:26:54 +0100 Subject: [PATCH] Add initial 'gdplint' tool structure --- gdtoolkit/gdplint/__init__.py | 7 ++++ gdtoolkit/gdplint/__main__.py | 58 ++++++++++++++++++++++++++++++ setup.py | 2 ++ tests/gdplint/__init__.py | 0 tests/gdplint/test_basic_checks.py | 13 +++++++ 5 files changed, 80 insertions(+) create mode 100644 gdtoolkit/gdplint/__init__.py create mode 100644 gdtoolkit/gdplint/__main__.py create mode 100644 tests/gdplint/__init__.py create mode 100644 tests/gdplint/test_basic_checks.py diff --git a/gdtoolkit/gdplint/__init__.py b/gdtoolkit/gdplint/__init__.py new file mode 100644 index 00000000..eaeab66f --- /dev/null +++ b/gdtoolkit/gdplint/__init__.py @@ -0,0 +1,7 @@ +from typing import List + +Problem = str # TODO: dataclass + + +def lint_project(_project_path) -> List[Problem]: + return [] diff --git a/gdtoolkit/gdplint/__main__.py b/gdtoolkit/gdplint/__main__.py new file mode 100644 index 00000000..f6ff88d3 --- /dev/null +++ b/gdtoolkit/gdplint/__main__.py @@ -0,0 +1,58 @@ +"""Godot Project linter + +A tool for diagnosing typical Godot project problems. +On success the exitcode is 0. +On failure, python exception or list of problems is shown and exitcode is non-zero. + +Usage: + gdplint ... [options] + +Options: + -v --verbose Show extra prints + -h --help Show this screen. + --version Show version. +""" +import sys +import pkg_resources +import logging +from typing import List + +from docopt import docopt + +from gdtoolkit.gdplint import lint_project + + +Path = str + + +def main(): + arguments = docopt( + __doc__, + version="gdlint {}".format(pkg_resources.get_distribution("gdtoolkit").version), + ) + + if arguments["--verbose"]: + logging.basicConfig(stream=sys.stdout, level=logging.INFO) + + problems_total = 0 + + project_paths: List[Path] = arguments[""] + for project_path in project_paths: + problems_total += _lint_project(project_path) + + if problems_total > 0: + print( + "Failure: {} problem{} found".format( + problems_total, "" if problems_total == 1 else "s" + ), + file=sys.stderr, + ) + sys.exit(1) + + print("Success: no problems found") + + +def _lint_project(project_path: Path) -> int: + outcome = lint_project(project_path) + print(outcome) + return len(outcome) diff --git a/setup.py b/setup.py index e49b7702..01f417de 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ "gdtoolkit.common", "gdtoolkit.gd2py", "gdtoolkit.gdradon", + "gdtoolkit.gdplint", ], package_data={"gdtoolkit.parser": ["gdscript.lark", "comments.lark"]}, entry_points={ @@ -27,6 +28,7 @@ "gdformat = gdtoolkit.formatter.__main__:main", "gd2py = gdtoolkit.gd2py.__main__:main", "gdradon = gdtoolkit.gdradon.__main__:main", + "gdplint = gdtoolkit.gdplint.__main__:main", ] }, include_package_data=True, diff --git a/tests/gdplint/__init__.py b/tests/gdplint/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/gdplint/test_basic_checks.py b/tests/gdplint/test_basic_checks.py new file mode 100644 index 00000000..7def5908 --- /dev/null +++ b/tests/gdplint/test_basic_checks.py @@ -0,0 +1,13 @@ +from gdtoolkit.gdplint import lint_project + +from ..common import write_file + +def test_valid_preload_path(tmp_path): + write_file(tmp_path, "script_a.gd", "") + write_file(tmp_path, "script_b.gd", "const A = preload(\"script_a.gd\")") + assert lint_project(tmp_path) == [] + +def test_invalid_preload_path(tmp_path): + write_file(tmp_path, "script_b.gd", "const A = preload(\"script_a.gd\")") + # assert lint_project(tmp_path) != [] + # TODO: check error precisely