From c62eecb27ef45d23a7b4d3f0e6cde55335be8ea4 Mon Sep 17 00:00:00 2001 From: clavedeluna Date: Mon, 19 Feb 2024 12:03:04 -0300 Subject: [PATCH] add ruff to makefile --- Makefile | 3 ++ src/core_codemods/file_resource_leak.py | 51 ------------------------- 2 files changed, 3 insertions(+), 51 deletions(-) diff --git a/Makefile b/Makefile index 49bed7af..2a5a2c0a 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,9 @@ integration-test: pygoat-test: ${PYTEST} -v ci_tests/test_pygoat_findings.py +lint: + ruff check src tests integration_tests --exclude tests/samples/ + radon: radon cc codemodder --min A --total-average diff --git a/src/core_codemods/file_resource_leak.py b/src/core_codemods/file_resource_leak.py index e2a2a6d5..49c2169f 100644 --- a/src/core_codemods/file_resource_leak.py +++ b/src/core_codemods/file_resource_leak.py @@ -307,57 +307,6 @@ def _last_ancestor_index(self, node, node_sequence) -> Optional[int]: last = i return last - def _find_direct_name_assignment_targets( - self, name: cst.Name - ) -> list[cst.BaseAssignTargetExpression]: - name_targets = [] - accesses = self.find_accesses(name) - for node in (access.node for access in accesses): - if maybe_assigned := self.is_value_of_assignment(node): - targets = extract_targets_of_assignment(maybe_assigned) - name_targets.extend(targets) - return name_targets - - def _find_name_assignment_targets( - self, name: cst.Name - ) -> tuple[list[cst.Name], list[cst.BaseAssignTargetExpression]]: - named_targets, other_targets = self._sieve_targets( - self._find_direct_name_assignment_targets(name) - ) - - for child in named_targets: - c_named_targets, c_other_targets = self._find_name_assignment_targets(child) - named_targets.extend(c_named_targets) - other_targets.extend(c_other_targets) - return named_targets, other_targets - - def _sieve_targets( - self, targets - ) -> tuple[list[cst.Name], list[cst.BaseAssignTargetExpression]]: - named_targets = [] - other_targets = [] - for t in targets: - # TODO maybe consider subscript here for named_targets - if isinstance(t, cst.Name): - named_targets.append(t) - else: - other_targets.append(t) - return named_targets, other_targets - - def _find_transitive_assignment_targets( - self, expr - ) -> tuple[list[cst.Name], list[cst.BaseAssignTargetExpression]]: - if maybe_assigned := self.is_value_of_assignment(expr): - named_targets, other_targets = self._sieve_targets( - extract_targets_of_assignment(maybe_assigned) - ) - for n in named_targets: - n_named_targets, n_other_targets = self._find_name_assignment_targets(n) - named_targets.extend(n_named_targets) - other_targets.extend(n_other_targets) - return named_targets, other_targets - return ([], []) - def _wrap_in_with_statement( self, stmts: list[SimpleStatementLine],