File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,11 @@ def from_result(cls, result: dict) -> Self:
4040 if not (rule_id := result .get ("rule" , None ) or result .get ("ruleKey" , None )):
4141 raise ValueError ("Could not extract rule id from sarif result." )
4242
43- locations : list [Location ] = [SonarLocation .from_json_location (result )]
43+ locations : list [Location ] = (
44+ [SonarLocation .from_json_location (result )]
45+ if result .get ("textRange" )
46+ else []
47+ )
4448 all_flows : list [list [Location ]] = [
4549 [
4650 SonarLocation .from_json_location (json_location )
Original file line number Diff line number Diff line change 1+ from core_codemods .sonar .results import SonarResult
2+
3+
4+ def test_result_without_textrange ():
5+ result = {
6+ "cleanCodeAttribute" : "FORMATTED" ,
7+ "cleanCodeAttributeCategory" : "CONSISTENT" ,
8+ "component" : "PixeeSandbox_DVWA:vulnerabilities/exec/help/help.php" ,
9+ "creationDate" : "2020-10-21T16:03:39+0200" ,
10+ "debt" : "2min" ,
11+ "effort" : "2min" ,
12+ "flows" : [],
13+ "impacts" : [{"severity" : "LOW" , "softwareQuality" : "MAINTAINABILITY" }],
14+ "issueStatus" : "OPEN" ,
15+ "key" : "AZJnP4pZPJb5bI8DP25Y" ,
16+ "message" : "Replace all tab characters in this file by sequences of "
17+ "white-spaces." ,
18+ "organization" : "pixee-sandbox" ,
19+ "project" : "PixeeSandbox_DVWA" ,
20+ "rule" : "php:S105" ,
21+ "severity" : "MINOR" ,
22+ "status" : "OPEN" ,
23+ "tags" : ["convention" , "psr2" ],
24+ "type" : "CODE_SMELL" ,
25+ "updateDate" : "2024-10-07T15:50:36+0200" ,
26+ }
27+ sonar_result = SonarResult .from_result (result )
28+ assert sonar_result .rule_id == "php:S105"
29+ assert sonar_result .finding_id == "AZJnP4pZPJb5bI8DP25Y"
30+ assert sonar_result .locations == []
31+ assert sonar_result .codeflows == []
You can’t perform that action at this time.
0 commit comments