11module internal Sarif
22
3- open FSharpLint.Framework
4- open System.IO
53open System
4+ open System.IO
65open Microsoft.CodeAnalysis .Sarif
76open Microsoft.CodeAnalysis .Sarif .Writers
7+ open FSharpLint.Framework
88open FSharpLint.Console .Output
99
1010let writeReport ( results : Suggestion.LintWarning list ) ( codeRoot : string option ) ( report : string ) ( logger : IOutput ) =
@@ -20,14 +20,15 @@ let writeReport (results: Suggestion.LintWarning list) (codeRoot: string option)
2020 let reportFile = FileInfo( report)
2121 reportFile.Directory.Create()
2222
23- let driver = ToolComponent()
24- driver.Name <- " FSharpLint.Console"
25- driver.InformationUri <- Uri( " https://fsprojects.github.io/FSharpLint/" )
26- driver.Version <- string< Version> ( System.Reflection.Assembly.GetExecutingAssembly() .GetName() .Version)
27- let tool = Tool()
28- tool.Driver <- driver
29- let run = Run()
30- run.Tool <- tool
23+ let driver =
24+ ToolComponent(
25+ Name = " FSharpLint.Console" ,
26+ InformationUri = Uri( " https://fsprojects.github.io/FSharpLint/" ),
27+ Version = string< Version> ( System.Reflection.Assembly.GetExecutingAssembly() .GetName() .Version)
28+ )
29+
30+ let tool = Tool( Driver = driver)
31+ let run = Run( Tool = tool)
3132
3233 use sarifLogger =
3334 new SarifLogger(
@@ -43,9 +44,14 @@ let writeReport (results: Suggestion.LintWarning list) (codeRoot: string option)
4344 sarifLogger.AnalysisStarted()
4445
4546 for analyzerResult in results do
46- let reportDescriptor = ReportingDescriptor()
47- reportDescriptor.Id <- analyzerResult.RuleIdentifier
48- reportDescriptor.Name <- analyzerResult.RuleName
47+ let helpUri = $" https://fsprojects.github.io/FSharpLint/how-tos/rules/%s {analyzerResult.RuleIdentifier}.html"
48+
49+ let reportDescriptor =
50+ ReportingDescriptor(
51+ Id = analyzerResult.RuleIdentifier,
52+ HelpUri = Uri( helpUri),
53+ Name = analyzerResult.RuleName
54+ )
4955
5056 (*
5157 analyzerResult.ShortDescription
@@ -55,12 +61,6 @@ let writeReport (results: Suggestion.LintWarning list) (codeRoot: string option)
5561 )
5662 *)
5763
58- let helpUri = $" https://fsprojects.github.io/FSharpLint/how-tos/rules/%s {analyzerResult.RuleIdentifier}.html"
59- reportDescriptor.HelpUri <- Uri( helpUri)
60-
61- let result = Result()
62- result.RuleId <- reportDescriptor.Id
63-
6464 (*
6565 result.Level <-
6666 match analyzerResult.Message.Severity with
@@ -69,30 +69,37 @@ let writeReport (results: Suggestion.LintWarning list) (codeRoot: string option)
6969 | Severity.Warning -> FailureLevel.Warning
7070 | Severity.Error -> FailureLevel.Error
7171 *)
72- result.Level <- FailureLevel.Warning
73-
74- let msg = Message()
75- msg.Text <- analyzerResult.Details.Message
76- result.Message <- msg
77-
78- let physicalLocation = PhysicalLocation()
79-
80- physicalLocation.ArtifactLocation <-
81- let al = ArtifactLocation()
82- al.Uri <- codeRoot.MakeRelativeUri( Uri( analyzerResult.Details.Range.FileName))
83- al
84-
85- physicalLocation.Region <-
86- let r = Region()
87- r.StartLine <- analyzerResult.Details.Range.StartLine
88- r.StartColumn <- analyzerResult.Details.Range.StartColumn + 1
89- r.EndLine <- analyzerResult.Details.Range.EndLine
90- r.EndColumn <- analyzerResult.Details.Range.EndColumn + 1
91- r
92-
93- let location : Location = Location()
94- location.PhysicalLocation <- physicalLocation
95- result.Locations <- [| location |]
72+
73+ let msg = Message( Text = analyzerResult.Details.Message)
74+
75+ let artifactLocation =
76+ ArtifactLocation(
77+ Uri = codeRoot.MakeRelativeUri( Uri( analyzerResult.Details.Range.FileName))
78+ )
79+
80+ let region =
81+ Region(
82+ StartLine = analyzerResult.Details.Range.StartLine,
83+ StartColumn = analyzerResult.Details.Range.StartColumn + 1 ,
84+ EndLine = analyzerResult.Details.Range.EndLine,
85+ EndColumn = analyzerResult.Details.Range.EndColumn + 1
86+ )
87+
88+ let physicalLocation =
89+ PhysicalLocation(
90+ ArtifactLocation = artifactLocation,
91+ Region = region
92+ )
93+
94+ let location = Location( PhysicalLocation = physicalLocation)
95+
96+ let result =
97+ Result(
98+ RuleId = reportDescriptor.Id,
99+ Level = FailureLevel.Warning,
100+ Locations = [| location |],
101+ Message = msg
102+ )
96103
97104 sarifLogger.Log( reportDescriptor, result, System.Nullable())
98105
0 commit comments