@@ -9,57 +9,57 @@ public class Converter1(FileInfo source, string? pathRoot)
99{
1010 public List < CodeQuality > Convert ( )
1111 {
12- Log . Information ( "Sarif Version 1 detected" ) ;
12+ Log . Information ( "Sarif Version 1 detected" ) ;
1313
14- var logContents = File . ReadAllText ( source . FullName ) ;
14+ var logContents = File . ReadAllText ( source . FullName ) ;
1515
16- var settings = new JsonSerializerSettings
17- {
18- ContractResolver = SarifContractResolverVersionOne . Instance
19- } ;
16+ var settings = new JsonSerializerSettings
17+ {
18+ ContractResolver = SarifContractResolverVersionOne . Instance
19+ } ;
2020
21- var log = JsonConvert . DeserializeObject < SarifLogVersionOne > ( logContents , settings ) ;
21+ var log = JsonConvert . DeserializeObject < SarifLogVersionOne > ( logContents , settings ) ;
2222
23- var results = log ? . Runs
24- . SelectMany ( x => x . Results )
25- . Where ( r => r . SuppressionStates == SuppressionStatesVersionOne . None ) ?? [ ] ;
23+ var results =
24+ log ? . Runs
25+ . SelectMany ( x => x . Results )
26+ . Where ( r => r . SuppressionStates == SuppressionStatesVersionOne . None ) ?? [ ] ;
2627
27- var cqrs = new List < CodeQuality > ( ) ;
28- foreach ( var result in results )
29- {
30- var begin = result . Locations ? . FirstOrDefault ( ) ;
28+ var cqrs = new List < CodeQuality > ( ) ;
29+ foreach ( var result in results )
30+ {
31+ var begin = result . Locations ? . FirstOrDefault ( ) ;
3132
32- if ( begin == null )
33- {
34- Log . Warning ( "An issue has no location, skipping: {Result}" , result . Message ) ;
35- continue ;
36- }
33+ if ( begin == null )
34+ {
35+ Log . Warning ( "An issue has no location, skipping: {Result}" , result . Message ) ;
36+ continue ;
37+ }
3738
38- try
39+ try
40+ {
41+ var cqr = new CodeQuality
3942 {
40- var cqr = new CodeQuality
43+ Description = $ "{ result . RuleId } : { result . Message } ",
44+ Severity = GetSeverity ( result . Level ) ,
45+ Location = new ( )
4146 {
42- Description = $ "{ result . RuleId } : { result . Message } ",
43- Severity = GetSeverity ( result . Level ) ,
44- Location = new ( )
45- {
46- Path = GetPath ( pathRoot , begin ) ,
47- Lines = new ( )
48- { Begin = begin . ResultFile . Region . StartLine }
49- } ,
50- Fingerprint = Common . GetHash (
47+ Path = GetPath ( pathRoot , begin ) ,
48+ Lines = new ( ) { Begin = begin . ResultFile . Region . StartLine }
49+ } ,
50+ Fingerprint = Common . GetHash (
5151 $ "{ result . RuleId } |{ begin . ResultFile . Uri } |{ begin . ResultFile . Region . StartLine } "
52- )
53- } ;
54- cqrs . Add ( cqr ) ;
55- }
56- catch ( Exception e )
57- {
58- Log . Error ( e , "Could not convert {@Result}, skipping" , result ) ;
59- }
52+ )
53+ } ;
54+ cqrs . Add ( cqr ) ;
6055 }
56+ catch ( Exception e )
57+ {
58+ Log . Error ( e , "Could not convert {@Result}, skipping" , result ) ;
59+ }
60+ }
6161
62- return cqrs ;
62+ return cqrs ;
6363 }
6464
6565 private static string GetPath ( string ? pathRoot , LocationVersionOne begin )
@@ -68,8 +68,8 @@ private static string GetPath(string? pathRoot, LocationVersionOne begin)
6868 if ( begin . ResultFile . Uri == null )
6969 {
7070 Log . Error (
71- "There is no valid Path for the issue {@Region}, cannot create a path. Check the source sarif for missing physicalLocation.uri" ,
72- begin . ResultFile . Region
71+ "There is no valid Path for the issue {@Region}, cannot create a path. Check the source sarif for missing physicalLocation.uri" ,
72+ begin . ResultFile . Region
7373 ) ;
7474 return "noPathInSourceSarif" ;
7575 }
@@ -114,4 +114,4 @@ private static string NormalizeSeparators(string source)
114114 {
115115 return source . Replace ( @"\\" , @"\" ) . Replace ( "//" , @"\" ) ;
116116 }
117- }
117+ }
0 commit comments