Skip to content

Commit 624a622

Browse files
committed
Fix 'expression-not-assigned' linter check
1 parent 092efcf commit 624a622

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

gdtoolkit/linter/basic_checks.py

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

66
from ..common.utils import find_name_token_among_children
7+
from ..formatter.expression_utils import remove_outer_parentheses
78

89
from .problem import Problem
910

@@ -62,9 +63,10 @@ def _expression_not_assigned_check(parse_tree: Tree) -> List[Problem]:
6263
problems = []
6364
for expr_stmt in parse_tree.find_data("expr_stmt"):
6465
expr = expr_stmt.children[0]
65-
child = expr.children[0]
66-
if not isinstance(child, Tree) or child.data not in [
66+
actual_expression = remove_outer_parentheses(expr.children[0])
67+
if not isinstance(actual_expression, Tree) or actual_expression.data not in [
6768
"assnmnt_expr",
69+
"await_expr",
6870
"standalone_call",
6971
"getattr_call",
7072
"string",
@@ -75,8 +77,8 @@ def _expression_not_assigned_check(parse_tree: Tree) -> List[Problem]:
7577
description=(
7678
"expression is not asigned, and hence it can be removed"
7779
),
78-
line=child.line,
79-
column=child.column,
80+
line=actual_expression.line,
81+
column=actual_expression.column,
8082
)
8183
)
8284
return problems

tests/linter/test_basic_checks.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@
2929
"""
3030
func foo():
3131
'''docstr'''
32+
""",
33+
"""
34+
func foo():
35+
await get_tree().create_timer(2.0).timeout
36+
""",
3237
"""
38+
func foo():
39+
('''docstr''')
40+
""",
3341
])
3442
def test_expression_not_assigned_ok(code):
3543
simple_ok_check(code)
@@ -42,6 +50,9 @@ def test_expression_not_assigned_ok(code):
4250
"""func foo():
4351
true
4452
""",
53+
"""func foo():
54+
(true)
55+
""",
4556
])
4657
def test_expression_not_assigned_nok(code):
4758
simple_nok_check(code, 'expression-not-assigned')

0 commit comments

Comments
 (0)