@@ -9,57 +9,57 @@ public class Converter1(FileInfo source, string? pathRoot)
9
9
{
10
10
public List < CodeQuality > Convert ( )
11
11
{
12
- Log . Information ( "Sarif Version 1 detected" ) ;
12
+ Log . Information ( "Sarif Version 1 detected" ) ;
13
13
14
- var logContents = File . ReadAllText ( source . FullName ) ;
14
+ var logContents = File . ReadAllText ( source . FullName ) ;
15
15
16
- var settings = new JsonSerializerSettings
17
- {
18
- ContractResolver = SarifContractResolverVersionOne . Instance
19
- } ;
16
+ var settings = new JsonSerializerSettings
17
+ {
18
+ ContractResolver = SarifContractResolverVersionOne . Instance
19
+ } ;
20
20
21
- var log = JsonConvert . DeserializeObject < SarifLogVersionOne > ( logContents , settings ) ;
21
+ var log = JsonConvert . DeserializeObject < SarifLogVersionOne > ( logContents , settings ) ;
22
22
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 ) ?? [ ] ;
26
27
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 ( ) ;
31
32
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
+ }
37
38
38
- try
39
+ try
40
+ {
41
+ var cqr = new CodeQuality
39
42
{
40
- var cqr = new CodeQuality
43
+ Description = $ "{ result . RuleId } : { result . Message } ",
44
+ Severity = GetSeverity ( result . Level ) ,
45
+ Location = new ( )
41
46
{
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 (
51
51
$ "{ 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 ) ;
60
55
}
56
+ catch ( Exception e )
57
+ {
58
+ Log . Error ( e , "Could not convert {@Result}, skipping" , result ) ;
59
+ }
60
+ }
61
61
62
- return cqrs ;
62
+ return cqrs ;
63
63
}
64
64
65
65
private static string GetPath ( string ? pathRoot , LocationVersionOne begin )
@@ -68,8 +68,8 @@ private static string GetPath(string? pathRoot, LocationVersionOne begin)
68
68
if ( begin . ResultFile . Uri == null )
69
69
{
70
70
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
73
73
) ;
74
74
return "noPathInSourceSarif" ;
75
75
}
@@ -114,4 +114,4 @@ private static string NormalizeSeparators(string source)
114
114
{
115
115
return source . Replace ( @"\\" , @"\" ) . Replace ( "//" , @"\" ) ;
116
116
}
117
- }
117
+ }
0 commit comments