Skip to content

Commit

Permalink
add match findings method to FileContext (#885)
Browse files Browse the repository at this point in the history
add match findings method
  • Loading branch information
clavedeluna authored Oct 21, 2024
1 parent 017211a commit bcdcc99
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/codemodder/file_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from codemodder.codetf import Change, ChangeSet, Finding, UnfixedFinding
from codemodder.dependency import Dependency
from codemodder.logging import logger
from codemodder.result import Result
from codemodder.utils.timer import Timer

Expand Down Expand Up @@ -60,6 +61,32 @@ def get_findings_for_location(self, line_number: int):
and result.finding is not None
]

def match_findings(self, line_numbers):
"""
Find the first finding that applies to any of the changed lines
NOTE: this is necessarily heuristic and may not always be correct
"""
findings = next(
(
findings
for line in line_numbers
if (findings := self.get_findings_for_location(line))
),
None,
)

if (
findings is None
and line_numbers
and any(result.finding for result in self.results or [])
):
logger.debug(
"Did not match line_numbers %s with one of these results: '%s'",
line_numbers,
self.results,
)
return findings

def get_all_findings(self):
return [
result.finding
Expand Down

0 comments on commit bcdcc99

Please sign in to comment.