Skip to content

Commit

Permalink
Remove 'private-method-call' linter check, fixes #308
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Aug 29, 2024
1 parent b696bd0 commit fcd3067
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 69 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [master]

### Changed
- Removed `private-method-call` linter check due to false positives when calling `super._foo()`

## [4.3.1] 2024-08-24

### Added
Expand Down
1 change: 0 additions & 1 deletion gdtoolkit/linter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
# unreachable # check in godot
# using-constant-test # check in godot
# class checks
"private-method-call": None,
"class-definitions-order": [
"tools",
"classnames",
Expand Down
44 changes: 3 additions & 41 deletions gdtoolkit/linter/class_checks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from functools import partial
from types import MappingProxyType
from typing import Callable, List, Tuple
from typing import List

from lark import Token, Tree
from lark import Tree

from ..common.ast import AbstractSyntaxTree, Class, Statement, Annotation
from ..common.utils import find_name_token_among_children, get_line, get_column
Expand All @@ -13,17 +13,6 @@

def lint(parse_tree: Tree, config: MappingProxyType) -> List[Problem]:
disable = config["disable"]
checks_to_run_w_tree = [
(
"private-method-call",
_private_method_call_check,
),
] # type: List[Tuple[str, Callable]]
problem_clusters = (
function(parse_tree) if name not in disable else []
for name, function in checks_to_run_w_tree
)
problems = [problem for cluster in problem_clusters for problem in cluster]
checks_to_run_w_ast = [
(
"class-definitions-order",
Expand All @@ -35,34 +24,7 @@ def lint(parse_tree: Tree, config: MappingProxyType) -> List[Problem]:
function(ast) if name not in disable else []
for name, function in checks_to_run_w_ast
)
problems += [problem for cluster in problem_clusters for problem in cluster]
return problems


def _private_method_call_check(parse_tree: Tree) -> List[Problem]:
problems = []
for getattr_call in parse_tree.find_data("getattr_call"):
_getattr = getattr_call.children[0]
callee_name_token = _getattr.children[-1]
callee_name = callee_name_token.value
called = _getattr.children[-3]
if (
isinstance(called, Token)
and called.type == "NAME"
and called.value == "self"
):
continue
if is_function_public(callee_name):
continue
problems.append(
Problem(
name="private-method-call",
description='Private method "{}" has been called'.format(callee_name),
line=get_line(callee_name_token),
column=get_column(callee_name_token),
)
)
return problems
return [problem for cluster in problem_clusters for problem in cluster]


def _class_definitions_order_check(
Expand Down
27 changes: 0 additions & 27 deletions tests/linter/test_class_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,6 @@


# fmt: off
@pytest.mark.parametrize('code', [
"""
var x = _foo()
""",
"""
var x = self._foo()
""",
"""
var x = a.b.c.foo()
""",
])
def test_private_method_call_ok(code):
simple_ok_check(code)


@pytest.mark.parametrize('code', [
"""
var x = y._foo()
""",
"""
var x = a.b.c._foo()
""",
])
def test_private_method_call_nok(code):
simple_nok_check(code, 'private-method-call')


@pytest.mark.parametrize('code', [
"""
pass
Expand Down

0 comments on commit fcd3067

Please sign in to comment.