Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Aug 13, 2024
1 parent 231e611 commit 186c254
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/codemodder/codemods/regex_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ def apply(


class SastRegexTransformerPipeline(RegexTransformerPipeline):
def line_matches_result(self, lineno, results) -> bool:
for result in results or []:
for location in result.locations:
if location.start.line == lineno:
return True
return False
def line_matches_result(self, lineno: int, result_linenums: list[int]) -> bool:
return lineno in result_linenums

def report_unfixed(self, file_context: FileContext, line_number: int, reason: str):
findings = file_context.get_findings_for_location(line_number)
Expand All @@ -94,8 +90,11 @@ def _apply(self, original_lines, file_context, results):
if results is not None and not results:
changes, updated_lines

result_linenums = [
location.start.line for result in results for location in result.locations
]
for lineno, line in enumerate(original_lines):
if self.line_matches_result(one_idx_lineno := lineno + 1, results):
if self.line_matches_result(one_idx_lineno := lineno + 1, result_linenums):
changed_line = self._apply_regex(line)
updated_lines.append(changed_line)
if line == changed_line:
Expand Down

0 comments on commit 186c254

Please sign in to comment.