Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code-root flag #157

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* [Properly walk SynModuleSigDecl.Val](https://github.com/ionide/FSharp.Analyzers.SDK/pull/156) (thanks @nojaf!)
* [Sarif file should not report absolute file paths](https://github.com/ionide/FSharp.Analyzers.SDK/issues/154) (thanks @nojaf!)

### Added
* [Add code-root flag](https://github.com/ionide/FSharp.Analyzers.SDK/pull/157) (thanks @nojaf!)

## [0.19.0] - 2023-11-08

### Changed
Expand Down
15 changes: 11 additions & 4 deletions src/FSharp.Analyzers.Cli/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Arguments =
| [<Unique>] Exclude_Analyzer of string list
| [<Unique>] Report of string
| [<Unique>] FSC_Args of string
| [<Unique>] Code_Root of string
| [<Unique>] Verbose

interface IArgParserTemplate with
Expand All @@ -41,6 +42,8 @@ type Arguments =
| Report _ -> "Write the result messages to a (sarif) report file."
| Verbose -> "Verbose logging."
| FSC_Args _ -> "Pass in the raw fsc compiler arguments. Cannot be combined with the `--project` flag."
| Code_Root _ ->
"Root of the current code repository, used in sarif report to the relative file path. The current working directory is used by default."
nojaf marked this conversation as resolved.
Show resolved Hide resolved

type SeverityMappings =
{
Expand Down Expand Up @@ -253,9 +256,12 @@ let printMessages (msgs: AnalyzerMessage list) =

()

let writeReport (results: AnalyzerMessage list option) (report: string) =
let writeReport (results: AnalyzerMessage list option) (codeRoot: string option) (report: string) =
try
let pwd = Directory.GetCurrentDirectory() |> Uri
let codeRoot =
match codeRoot with
| None -> Directory.GetCurrentDirectory() |> Uri
| Some root -> Path.GetFullPath root |> Uri

// Construct full path to ensure path separators are normalized.
let report = Path.GetFullPath report
Expand Down Expand Up @@ -317,7 +323,7 @@ let writeReport (results: AnalyzerMessage list option) (report: string) =

physicalLocation.ArtifactLocation <-
let al = ArtifactLocation()
al.Uri <- pwd.MakeRelativeUri(Uri(analyzerResult.Message.Range.FileName))
al.Uri <- codeRoot.MakeRelativeUri(Uri(analyzerResult.Message.Range.FileName))
al

physicalLocation.Region <-
Expand Down Expand Up @@ -441,6 +447,7 @@ let main argv =
let projOpts = results.GetResults <@ Project @> |> List.concat
let fscArgs = results.TryGetResult <@ FSC_Args @>
let report = results.TryGetResult <@ Report @>
let codeRoot = results.TryGetResult <@ Code_Root @>

let results =
if analyzers = 0 then
Expand Down Expand Up @@ -470,6 +477,6 @@ let main argv =
|> Some

results |> Option.iter printMessages
report |> Option.iter (writeReport results)
report |> Option.iter (writeReport results codeRoot)

calculateExitCode results