diff --git a/CHANGELOG.md b/CHANGELOG.md index a27de0df..4f213b1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/gdtoolkit/linter/__init__.py b/gdtoolkit/linter/__init__.py index c5e8beeb..c9ff5c06 100644 --- a/gdtoolkit/linter/__init__.py +++ b/gdtoolkit/linter/__init__.py @@ -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", diff --git a/gdtoolkit/linter/class_checks.py b/gdtoolkit/linter/class_checks.py index e51a7e46..6c6fc82c 100644 --- a/gdtoolkit/linter/class_checks.py +++ b/gdtoolkit/linter/class_checks.py @@ -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 @@ -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", @@ -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( diff --git a/tests/linter/test_class_checks.py b/tests/linter/test_class_checks.py index f5976ebb..a3ed3b72 100644 --- a/tests/linter/test_class_checks.py +++ b/tests/linter/test_class_checks.py @@ -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