Skip to content

Commit 9d84051

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents fc172c0 + 1eee0cb commit 9d84051

55 files changed

Lines changed: 1160 additions & 171 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ko_fi: pawel_lampe

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Python
1616
uses: actions/setup-python@v5
1717
with:
18-
python-version: '3.7'
18+
python-version: '3.8'
1919

2020
- name: Install pypa/build
2121
run: >-

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
12+
python-version: [3.9, '3.10', '3.11', '3.12']
1313
os: [ubuntu-latest, windows-latest, macos-latest]
1414

1515
steps:

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,39 @@
22

33
## [master]
44

5+
### Added
6+
- Added support for @abstract functions
7+
8+
### Changed
9+
- Fixed formatting of `@warning_ignore_start` and `@warning_ignore_restore`
10+
- Fixed formatting of `shadowed_variable*` ignore annotations
11+
12+
## [4.3.4] 2025-06-29
13+
14+
### Changed
15+
- Fixed linter problem reports when global scope is used
16+
- Fixed formatting of certain `@warning_ignore` annotations
17+
18+
## [4.3.3] 2024-11-02
19+
20+
### Changed
21+
- Fixed false-positive `expression-not-assigned` linter check on lambdas
22+
- Fixed erroneous DedentError raised in case of inline lambas
23+
24+
## [4.3.2] 2024-10-20
25+
526
### Added
627
- Added support for multi-statement lambdas (#191)
28+
- Added support for typed dictionaries (#322)
729

830
### Changed
931
- Removed `private-method-call` linter check due to false positives when calling `super._foo()`
1032
- Fixed support for `get_node` syntax to accommodate for `$/(...)`
33+
- Fixed `gd2py` and `gdradon` to support latest GDScript
1134
- Changed formatting of some uni-statement lambdas
1235
- Changed formatting of multi-statement, inline lambdas
36+
- Changed formatting of dot-chains containing a lambda(s)
37+
- Changed linter check `class-definitions-order` in a way that static class variables are recommended to be placed just after constants
1338

1439
## [4.3.1] 2024-08-24
1540

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# GDScript Toolkit
2-
[![](https://github.com/Scony/godot-gdscript-toolkit/workflows/Tests/badge.svg?branch=master)](https://github.com/Scony/godot-gdscript-toolkit/actions)
2+
[![](https://github.com/Scony/godot-gdscript-toolkit/workflows/Tests/badge.svg)](https://github.com/Scony/godot-gdscript-toolkit/actions)
33
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
44
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
5+
[![Buy me a coffe](https://img.shields.io/badge/Buy%20me%20a%20coffe-FF5E5B?logo=ko-fi&logoColor=white)](https://ko-fi.com/pawel_lampe)
56

67
This project provides a set of tools for daily work with `GDScript`. At the moment it provides:
78

@@ -165,6 +166,34 @@ jobs:
165166

166167
See the discussion in https://github.com/Scony/godot-gdscript-toolkit/issues/239 for more details.
167168

169+
## Using gdtookit in pre-commit
170+
171+
To add gdtookit as a pre-commit hook check the latest GitHub version (eg `4.2.2`) and add the followingto your `pre-commit-config.yaml` with the latest version.
172+
173+
```Yaml
174+
repos:
175+
# GDScript Toolkit
176+
- repo: https://github.com/Scony/godot-gdscript-toolkit
177+
rev: 4.2.2
178+
hooks:
179+
- id: gdlint
180+
name: gdlint
181+
description: "gdlint - linter for GDScript"
182+
entry: gdlint
183+
language: python
184+
language_version: python3
185+
require_serial: true
186+
types: [gdscript]
187+
- id: gdformat
188+
name: gdformat
189+
description: "gdformat - formatter for GDScript"
190+
entry: gdformat
191+
language: python
192+
language_version: python3
193+
require_serial: true
194+
types: [gdscript]
195+
```
196+
168197
## Development [(more)](https://github.com/Scony/godot-gdscript-toolkit/wiki/5.-Development)
169198
170199
Everyone is free to fix bugs or introduce new features. For that, however, please refer to existing issue or create one before starting implementation.

gdtoolkit/common/ast.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from lark import Tree
55

6-
from ..formatter.annotation import STANDALONE_ANNOTATIONS
6+
from ..formatter.annotation import is_non_standalone_annotation
77

88
from .utils import find_name_token_among_children, find_tree_among_children
99
from .exceptions import GDToolkitError
@@ -39,6 +39,9 @@ def _load_sub_statements(self):
3939
raise NotImplementedError
4040
if self.kind in ["func_def", "static_func_def"]:
4141
self.sub_statements = [Statement(n) for n in self.lark_node.children[1:]]
42+
elif self.kind == "abstract_func_def":
43+
# Abstract functions don't have a body, so no sub-statements
44+
pass
4245
elif self.kind == "if_stmt":
4346
for branch in self.lark_node.children:
4447
if branch.data in ["if_branch", "elif_branch"]:
@@ -114,6 +117,7 @@ def __init__(self, parse_tree: Tree):
114117
if parse_tree.data == "start":
115118
start = parse_tree
116119
self._load_data_from_node_children(start)
120+
self.name = "global scope"
117121
elif parse_tree.data == "class_def":
118122
self._load_data_from_class_def(parse_tree)
119123
else:
@@ -123,9 +127,7 @@ def _load_data_from_node_children(self, node: Tree) -> None:
123127
offset = 1 if node.data == "class_def" else 0
124128
annotations = []
125129
for stmt in node.children[offset:]:
126-
if stmt.data == "annotation" and not _is_annotation_standalone(
127-
Annotation(stmt)
128-
):
130+
if stmt.data == "annotation" and is_non_standalone_annotation(stmt):
129131
annotations.append(Annotation(stmt))
130132
continue
131133
if stmt.data == "property_body_def":
@@ -142,6 +144,10 @@ def _load_data_from_node_children(self, node: Tree) -> None:
142144
function = Function(stmt)
143145
self.functions.append(function)
144146
self.all_functions.append(function)
147+
if stmt.data == "abstract_func_def":
148+
function = Function(stmt)
149+
self.functions.append(function)
150+
self.all_functions.append(function)
145151

146152
def _load_data_from_class_def(self, class_def: Tree) -> None:
147153
name_token = find_name_token_among_children(class_def)
@@ -158,7 +164,3 @@ def __init__(self, parse_tree: Tree):
158164
self.root_class = Class(parse_tree)
159165
self.all_classes = [self.root_class] + self.root_class.all_sub_classes
160166
self.all_functions = self.root_class.all_functions
161-
162-
163-
def _is_annotation_standalone(annotation: Annotation) -> bool:
164-
return annotation.name in STANDALONE_ANNOTATIONS

gdtoolkit/formatter/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@
1515
DEFAULT_CONFIG = MappingProxyType(
1616
{
1717
"excluded_directories": {".git"},
18+
"safety_checks": None,
19+
"use_spaces": None,
20+
"line_length": 100,
1821
}
1922
)
2023

2124

2225
# pylint: disable-next=too-many-arguments
26+
# pylint: disable=too-many-positional-arguments
27+
# pylint: disable=too-many-arguments
2328
def check_formatting_safety(
2429
given_code: str,
2530
formatted_code: str,

gdtoolkit/formatter/__main__.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
(implies --check).
1717
-f --fast Skip safety checks.
1818
-l --line-length=<int> How many characters per line to allow.
19-
[default: 100]
2019
-s --use-spaces=<int> Use spaces for indent instead of tabs.
2120
-h --help Show this screen.
2221
--version Show version.
@@ -25,14 +24,15 @@
2524
Examples:
2625
echo 'pass' | gdformat - # reads from STDIN
2726
"""
27+
2828
import sys
2929
import os
3030
import logging
3131
import pathlib
3232
import difflib
3333
from typing import List, Tuple, Optional
3434
from types import MappingProxyType
35-
import pkg_resources
35+
from importlib.metadata import version as pkg_version
3636

3737
from docopt import docopt
3838
import lark
@@ -58,9 +58,7 @@ def main():
5858
sys.stdout.reconfigure(encoding="utf-8")
5959
arguments = docopt(
6060
__doc__,
61-
version="gdformat {} (kuruk-mm fork)".format(
62-
pkg_resources.get_distribution("gdtoolkit").version
63-
),
61+
version="gdformat {} (kuruk-mm fork)".format(pkg_version("gdtoolkit")),
6462
)
6563

6664
if arguments["--dump-default-config"]:
@@ -69,14 +67,6 @@ def main():
6967
if arguments["--diff"]:
7068
arguments["--check"] = True
7169

72-
line_length = int(arguments["--line-length"])
73-
spaces_for_indent = (
74-
int(arguments["--use-spaces"])
75-
if arguments["--use-spaces"] is not None
76-
else None
77-
)
78-
safety_checks = not arguments["--fast"]
79-
8070
config_file_path = _find_config_file()
8171
config = _load_config_file_or_default(config_file_path)
8272
_log_config_entries(config)
@@ -86,6 +76,24 @@ def main():
8676
arguments["<path>"], excluded_directories=set(config["excluded_directories"])
8777
)
8878

79+
line_length = (
80+
int(arguments["--line-length"])
81+
if arguments["--line-length"]
82+
else config.get("line_length", DEFAULT_CONFIG["line_length"])
83+
)
84+
85+
spaces_for_indent = (
86+
int(arguments["--use-spaces"])
87+
if arguments["--use-spaces"]
88+
else config.get("use_spaces", DEFAULT_CONFIG["use_spaces"])
89+
)
90+
91+
safety_checks = (
92+
not arguments["--fast"]
93+
if arguments.get("--fast")
94+
else config.get("safety_checks", DEFAULT_CONFIG["safety_checks"])
95+
)
96+
8997
if files == ["-"]:
9098
_format_stdin(line_length, spaces_for_indent, safety_checks)
9199
elif arguments["--check"]:
@@ -312,6 +320,14 @@ def _format_code(
312320
sep="\n",
313321
file=sys.stderr,
314322
)
323+
except lark.indenter.DedentError as exception:
324+
success = False
325+
print(
326+
f"{file_path}:\n",
327+
str(exception),
328+
sep="\n",
329+
file=sys.stderr,
330+
)
315331
except TreeInvariantViolation:
316332
success = False
317333
print(

0 commit comments

Comments
 (0)