Skip to content

Commit

Permalink
Add initial 'gdplint' tool structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Dec 19, 2022
1 parent 0287c4a commit 8df5723
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gdtoolkit/gdplint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from typing import List

Problem = str # TODO: dataclass


def lint_project(_project_path) -> List[Problem]:
return []
58 changes: 58 additions & 0 deletions gdtoolkit/gdplint/__main__.py
Original file line number Diff line number Diff line change
@@ -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 <project_path>... [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["<project_path>"]
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)
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"gdtoolkit.common",
"gdtoolkit.gd2py",
"gdtoolkit.gdradon",
"gdtoolkit.gdplint",
],
package_data={"gdtoolkit.parser": ["gdscript.lark", "comments.lark"]},
entry_points={
Expand All @@ -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,
Expand Down
Empty file added tests/gdplint/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions tests/gdplint/test_basic_checks.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8df5723

Please sign in to comment.