Skip to content

Commit

Permalink
Use proper finding IDs for sonar and semgrep SARIF
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Dec 19, 2024
1 parent b4d64d7 commit 7a40b51
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/codemodder/semgrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,18 @@ def from_sarif(
# avoid circular import
from core_codemods.semgrep.api import semgrep_url_from_id

rule_id = cls.extract_rule_id(sarif_result, sarif_run, truncate_rule_id)
finding_id = cls.extract_finding_id(sarif_result) or rule_id
return cls(
rule_id=(
rule_id := cls.extract_rule_id(
sarif_result, sarif_run, truncate_rule_id
)
),
rule_id=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_id=finding_id,
finding=Finding(
id=rule_id,
id=cls.extract_finding_id(sarif_result) or rule_id,
rule=Rule(
id=rule_id,
id=finding_id,
name=rule_id,
url=semgrep_url_from_id(rule_id),
),
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/sonar/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def from_result(cls, result: dict) -> Self:
locations=locations,
codeflows=all_flows,
finding=Finding(
id=rule_id,
id=finding_id,
rule=Rule(
id=rule_id,
name=name,
Expand Down

0 comments on commit 7a40b51

Please sign in to comment.