From 8d0af71625549f7713a8e4ae5ed54c43c1f969b1 Mon Sep 17 00:00:00 2001 From: Dan D'Avella Date: Fri, 20 Dec 2024 14:51:26 -0500 Subject: [PATCH] Fix finding IDs for semgrep sarifs (#960) --- src/codemodder/semgrep.py | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/src/codemodder/semgrep.py b/src/codemodder/semgrep.py index 7c6e7a32..5884f1e2 100644 --- a/src/codemodder/semgrep.py +++ b/src/codemodder/semgrep.py @@ -7,7 +7,6 @@ from typing_extensions import Self, override -from codemodder.codetf import Finding, Rule from codemodder.context import CodemodExecutionContext from codemodder.logging import logger from codemodder.result import LineInfo, Result, ResultSet, SarifLocation, SarifResult @@ -48,31 +47,11 @@ class SemgrepResult(SarifResult): location_type = SemgrepLocation @classmethod - def from_sarif( - cls, sarif_result, sarif_run, truncate_rule_id: bool = False - ) -> Self: - # avoid circular import + def rule_url_from_id(cls, sarif_result, sarif_run, rule_id): + del sarif_result, sarif_run from core_codemods.semgrep.api import semgrep_url_from_id - return cls( - rule_id=( - rule_id := cls.extract_rule_id( - sarif_result, sarif_run, truncate_rule_id - ) - ), - locations=cls.extract_locations(sarif_result), - codeflows=cls.extract_code_flows(sarif_result), - related_locations=cls.extract_related_locations(sarif_result), - finding_id=rule_id, - finding=Finding( - id=rule_id, - rule=Rule( - id=rule_id, - name=rule_id, - url=semgrep_url_from_id(rule_id), - ), - ), - ) + return semgrep_url_from_id(rule_id) class SemgrepResultSet(ResultSet):