Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andrecsilva committed Jan 26, 2024
1 parent d642ec8 commit 1d316cb
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 27 deletions.
2 changes: 1 addition & 1 deletion integration_tests/test_sonar_numpy_nan_equality.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from core_codemods.sonar_numpy_nan_equality import (
from core_codemods.sonar.sonar_numpy_nan_equality import (
SonarNumpyNanEquality,
SonarNumpyNanEqualityTransformer,
)
Expand Down
8 changes: 0 additions & 8 deletions src/codemodder/codemodder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from codemodder.report.codetf_reporter import report_default
from codemodder.result import ResultSet
from codemodder.semgrep import run as run_semgrep
from codemodder.sonar_results import SonarResultSet


def update_code(file_path, new_code):
Expand Down Expand Up @@ -137,13 +136,6 @@ def record_dependency_update(dependency_results: dict[Dependency, PackageStore |
logger.debug("The following dependencies could not be added: %s", str_list)


def process_sonar_findings(sonar_json_files: list[str]) -> SonarResultSet:
combined_result_set = SonarResultSet()
for file in sonar_json_files or []:
combined_result_set |= SonarResultSet.from_json(file)
return combined_result_set


def run(original_args) -> int:
start = datetime.datetime.now()

Expand Down
4 changes: 2 additions & 2 deletions src/codemodder/codemods/base_codemod.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ def docs_module(self) -> Traversable:

@cached_property
def description(self) -> str:
if self._metadata.description == None:
if self._metadata.description is None:
doc_path = self.docs_module / f"{self.origin}_python_{self.name}.md"
return doc_path.read_text()
return self._metadata.description # type: ignore
return self._metadata.description

@property
def review_guidance(self):
Expand Down
5 changes: 1 addition & 4 deletions src/codemodder/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ def __init__(
self.path_include = path_include
self.path_exclude = path_exclude
self.max_workers = max_workers
if tool_result_files_map:
self.tool_result_files_map = tool_result_files_map
else:
self.tool_result_files_map = {}
self.tool_result_files_map = tool_result_files_map or {}

def add_results(self, codemod_name: str, change_sets: List[ChangeSet]):
self._results_by_codemod.setdefault(codemod_name, []).extend(change_sets)
Expand Down
15 changes: 6 additions & 9 deletions src/codemodder/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,12 @@ def match_codemods(
) -> list[BaseCodemod]:
codemod_include = codemod_include or []
codemod_exclude = codemod_exclude or DEFAULT_EXCLUDED_CODEMODS

if sast_only:
base_list = [
codemod for codemod in self.codemods if codemod.origin != "pixee"
]
else:
base_list = [
codemod for codemod in self.codemods if codemod.origin == "pixee"
]
base_list = [
codemod
for codemod in self.codemods
if (sast_only and codemod.origin != "pixee")
or (not sast_only and codemod.origin == "pixee")
]

if codemod_exclude and not codemod_include:
return [
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from .remove_assertion_in_pytest_raises import RemoveAssertionInPytestRaises
from .fix_assert_tuple import FixAssertTuple

from .sonar_numpy_nan_equality import SonarNumpyNanEquality
from .sonar.sonar_numpy_nan_equality import SonarNumpyNanEquality

registry = CodemodCollection(
origin="pixee",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/codemods/test_sonar_numpy_nan_equality.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from core_codemods.sonar_numpy_nan_equality import SonarNumpyNanEquality
from core_codemods.sonar.sonar_numpy_nan_equality import SonarNumpyNanEquality
from tests.codemods.base_codemod_test import BaseSASTCodemodTest
from textwrap import dedent

Expand Down
1 change: 0 additions & 1 deletion tests/test_codemod_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def pytest_generate_tests(metafunc):


def test_load_codemod_docs_info(codemod: BaseCodemod):
print(codemod.name)
if codemod.name in ["order-imports"]:
pytest.xfail(reason=f"{codemod.name} has no description")

Expand Down

0 comments on commit 1d316cb

Please sign in to comment.