Skip to content

Commit bcdcc99

Browse files
authored
add match findings method to FileContext (#885)
add match findings method
1 parent 017211a commit bcdcc99

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/codemodder/file_context.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from codemodder.codetf import Change, ChangeSet, Finding, UnfixedFinding
55
from codemodder.dependency import Dependency
6+
from codemodder.logging import logger
67
from codemodder.result import Result
78
from codemodder.utils.timer import Timer
89

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

64+
def match_findings(self, line_numbers):
65+
"""
66+
Find the first finding that applies to any of the changed lines
67+
NOTE: this is necessarily heuristic and may not always be correct
68+
"""
69+
findings = next(
70+
(
71+
findings
72+
for line in line_numbers
73+
if (findings := self.get_findings_for_location(line))
74+
),
75+
None,
76+
)
77+
78+
if (
79+
findings is None
80+
and line_numbers
81+
and any(result.finding for result in self.results or [])
82+
):
83+
logger.debug(
84+
"Did not match line_numbers %s with one of these results: '%s'",
85+
line_numbers,
86+
self.results,
87+
)
88+
return findings
89+
6390
def get_all_findings(self):
6491
return [
6592
result.finding

0 commit comments

Comments
 (0)