Skip to content

Commit

Permalink
Add RequireQualifiedAccess to Severity type
Browse files Browse the repository at this point in the history
  • Loading branch information
Smaug123 committed Jan 26, 2024
1 parent 1aa73ad commit 4a71ecb
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased

### Changed
* [Add `RequireQualifiedAccess` to `Severity` type](https://github.com/ionide/FSharp.Analyzers.SDK/pull/199) (thanks @Smaug123!)
* [Fail the tool when any analyzers fail to load](https://github.com/ionide/FSharp.Analyzers.SDK/pull/198) (thanks @Smaug123!)

## [0.23.0] - 2024-01-05
Expand Down
2 changes: 1 addition & 1 deletion docs/content/Dual Analyzer.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ let private topologicallySortedOpenStatementsAnalyzer
Type = "Unsorted System open statement"
Message = $"%s{openStatementText} was found after non System namespaces where opened!"
Code = "SOT001"
Severity = Warning
Severity = Severity.Warning
Range = mOpen
Fixes = []
}
Expand Down
2 changes: 1 addition & 1 deletion docs/content/Getting Started Writing.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let optionValueAnalyzer: Analyzer<CliContext> =
Type = "Option.Value analyzer"
Message = "Option.Value shouldn't be used"
Code = "OV001"
Severity = Warning
Severity = Severity.Warning
Range = FSharp.Compiler.Text.Range.Zero
Fixes = []
}
Expand Down
2 changes: 1 addition & 1 deletion samples/OptionAnalyzer/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let optionValueAnalyzer: Analyzer<CliContext> =
Type = "Option.Value analyzer"
Message = "Option.Value shouldn't be used"
Code = "OV001"
Severity = Warning
Severity = Severity.Warning
Range = r
Fixes = []
}
Expand Down
28 changes: 14 additions & 14 deletions src/FSharp.Analyzers.Cli/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ type SeverityMappings =
let mapMessageToSeverity (mappings: SeverityMappings) (msg: FSharp.Analyzers.SDK.AnalyzerMessage) =
let targetSeverity =
if mappings.TreatAsInfo |> Set.contains msg.Message.Code then
Info
Severity.Info
else if mappings.TreatAsHint |> Set.contains msg.Message.Code then
Hint
Severity.Hint
else if mappings.TreatAsWarning |> Set.contains msg.Message.Code then
Warning
Severity.Warning
else if mappings.TreatAsError |> Set.contains msg.Message.Code then
Error
Severity.Error
else
msg.Message.Severity

Expand Down Expand Up @@ -247,10 +247,10 @@ let printMessages (msgs: AnalyzerMessage list) =
let severityToLogLevel =
Map.ofArray
[|
Error, LogLevel.Error
Warning, LogLevel.Warning
Info, LogLevel.Information
Hint, LogLevel.Trace
Severity.Error, LogLevel.Error
Severity.Warning, LogLevel.Warning
Severity.Info, LogLevel.Information
Severity.Hint, LogLevel.Trace
|]

if List.isEmpty msgs then
Expand All @@ -276,7 +276,7 @@ let printMessages (msgs: AnalyzerMessage list) =
m.Range.FileName,
m.Range.StartLine,
m.Range.StartColumn,
(m.Severity.ToString()),
m.Severity.ToString(),
m.Code,
m.Message
)
Expand Down Expand Up @@ -338,10 +338,10 @@ let writeReport (results: AnalyzerMessage list option) (codeRoot: string option)

result.Level <-
match analyzerResult.Message.Severity with
| Info -> FailureLevel.Note
| Hint -> FailureLevel.Note
| Warning -> FailureLevel.Warning
| Error -> FailureLevel.Error
| Severity.Info -> FailureLevel.Note
| Severity.Hint -> FailureLevel.Note
| Severity.Warning -> FailureLevel.Warning
| Severity.Error -> FailureLevel.Error

let msg = Message()
msg.Text <- analyzerResult.Message.Message
Expand Down Expand Up @@ -384,7 +384,7 @@ let calculateExitCode (msgs: AnalyzerMessage list option) : int =
|> List.exists (fun analyzerMessage ->
let message = analyzerMessage.Message

message.Severity = Error
message.Severity = Severity.Error
)

if check then -2 else 0
Expand Down
1 change: 1 addition & 0 deletions src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.fs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ type Fix =
ToText: string
}

[<RequireQualifiedAccess>]
type Severity =
| Info
| Hint
Expand Down
1 change: 1 addition & 0 deletions src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type Fix =
ToText: string
}

[<RequireQualifiedAccess>]
type Severity =
| Info
| Hint
Expand Down

0 comments on commit 4a71ecb

Please sign in to comment.