Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add match findings method to FileContext #885

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading