Skip to content

Commit fc94c28

Browse files
committed
Fix linter support for trailing comma in function's args list, fixes Scony#206
1 parent 7680aa6 commit fc94c28

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Default regex for names of constants now allows underscore as a prefix to denote private contants (#223)
1212
- Fixed parsing of files without newline at the end of file ending with comment (#237)
1313
- Fixed linter support for docstrings (#233)
14+
- Fixed linter support for trailing comma in function's args list (#206)
1415

1516
## [4.1.0] 2023-07-06
1617

gdtoolkit/linter/basic_checks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from lark import Tree, Token
55

66
from ..common.utils import find_name_token_among_children, get_line, get_column
7-
from ..formatter.expression_utils import remove_outer_parentheses
7+
from ..formatter.expression_utils import remove_outer_parentheses, is_trailing_comma
88

99
from .problem import Problem
1010

@@ -127,7 +127,7 @@ def _unused_argument_check(parse_tree: Tree) -> List[Problem]:
127127
argument_definitions = {} # type: Dict[str, int]
128128
argument_tokens = {}
129129
func_args = func_header.children[1]
130-
for func_arg in func_args.children:
130+
for func_arg in [r for r in func_args.children if not is_trailing_comma(r)]:
131131
arg_name_token = find_name_token_among_children(func_arg)
132132
arg_name = arg_name_token.value # type: ignore
133133
argument_definitions[arg_name] = (

tests/linter/test_basic_corner_cases.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ def test_newlineless_code():
1414
def test_docstring():
1515
code = '"""\nhello world!\n"""'
1616
lint_code(code)
17+
18+
19+
def test_trailing_comma_in_params_list():
20+
code = """static func _is_agent_placement_position_valid(
21+
position,
22+
radius,
23+
existing_units,
24+
navigation_map_rid,):pass"""
25+
lint_code(code)

0 commit comments

Comments
 (0)