-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a false negative in LoggingTemplateMissingValuesAnalyzer (#80)
* fix a false negative caused by not diving into match clauses * add changelog entry and release 0.9.1 * Update CHANGELOG.md Co-authored-by: Florian Verdonck <[email protected]> * remove test file from item group * add comment about non-tailrec function * detect template strings constructed by functions like sprintf * add changelog entry and release --------- Co-authored-by: Florian Verdonck <[email protected]>
- Loading branch information
Showing
11 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...Sharp.Analyzers.Tests/data/loggingtemplatemissingvalues/Warnings for function template.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module M | ||
|
||
open Microsoft.Extensions.Logging | ||
|
||
let testlog () = | ||
use factory = LoggerFactory.Create(fun b -> b.AddConsole() |> ignore) | ||
let logger: ILogger = factory.CreateLogger("Program") | ||
let timeWasteString = "time waste" | ||
|
||
logger.LogWarning(id "Foo {Wasted}\n{Result}", timeWasteString) |
1 change: 1 addition & 0 deletions
1
...lyzers.Tests/data/loggingtemplatemissingvalues/Warnings for function template.fs.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GRA-LOGTEMPLMISSVALS-001 | Warning | (10,8 - 10,71) | The given values in your call to ILogger.LogWarning don't match the expected templated args. | [] |
11 changes: 11 additions & 0 deletions
11
...FSharp.Analyzers.Tests/data/loggingtemplatemissingvalues/Warnings for sprintf template.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module M | ||
|
||
open Microsoft.Extensions.Logging | ||
|
||
let testlog () = | ||
use factory = LoggerFactory.Create(fun b -> b.AddConsole() |> ignore) | ||
let logger: ILogger = factory.CreateLogger("Program") | ||
let timespan = System.TimeSpan() | ||
let timeWasteString = "time waste" | ||
|
||
logger.LogWarning(sprintf "Foo %dm %ds {Wasted}\n{Result}" (int timespan.TotalMinutes) timespan.Seconds, timeWasteString) |
1 change: 1 addition & 0 deletions
1
...alyzers.Tests/data/loggingtemplatemissingvalues/Warnings for sprintf template.fs.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GRA-LOGTEMPLMISSVALS-001 | Warning | (11,8 - 11,129) | The given values in your call to ILogger.LogWarning don't match the expected templated args. | [] |
10 changes: 10 additions & 0 deletions
10
...Sharp.Analyzers.Tests/data/loggingtemplatemissingvalues/Warnings for sprintf template2.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module M | ||
|
||
open Microsoft.Extensions.Logging | ||
|
||
let testlog () = | ||
use factory = LoggerFactory.Create(fun b -> b.AddConsole() |> ignore) | ||
let logger: ILogger = factory.CreateLogger("Program") | ||
let timeWasteString = "time waste" | ||
|
||
logger.LogWarning(sprintf "Foo {Wasted}\n{Result}", timeWasteString) |
1 change: 1 addition & 0 deletions
1
...lyzers.Tests/data/loggingtemplatemissingvalues/Warnings for sprintf template2.fs.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GRA-LOGTEMPLMISSVALS-001 | Warning | (10,8 - 10,76) | The given values in your call to ILogger.LogWarning don't match the expected templated args. | [] |
12 changes: 12 additions & 0 deletions
12
...ers.Tests/data/loggingtemplatemissingvalues/negative/No warnings for function template.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module M | ||
|
||
open Microsoft.Extensions.Logging | ||
|
||
let testlog () = | ||
use factory = LoggerFactory.Create(fun b -> b.AddConsole() |> ignore) | ||
let logger: ILogger = factory.CreateLogger("Program") | ||
let timespan = System.TimeSpan() | ||
let timeWasteString = "time waste" | ||
let result = "result" | ||
|
||
logger.LogWarning(id "Foo {Wasted}\n{Result}", timeWasteString, result) |
12 changes: 12 additions & 0 deletions
12
...zers.Tests/data/loggingtemplatemissingvalues/negative/No warnings for sprintf template.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module M | ||
|
||
open Microsoft.Extensions.Logging | ||
|
||
let testlog () = | ||
use factory = LoggerFactory.Create(fun b -> b.AddConsole() |> ignore) | ||
let logger: ILogger = factory.CreateLogger("Program") | ||
let timespan = System.TimeSpan() | ||
let timeWasteString = "time waste" | ||
let result = "result" | ||
|
||
logger.LogWarning(sprintf "Foo %dm %ds {Wasted}\n{Result}" (int timespan.TotalMinutes) timespan.Seconds, timeWasteString, result) |
12 changes: 12 additions & 0 deletions
12
...ers.Tests/data/loggingtemplatemissingvalues/negative/No warnings for sprintf template2.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module M | ||
|
||
open Microsoft.Extensions.Logging | ||
|
||
let testlog () = | ||
use factory = LoggerFactory.Create(fun b -> b.AddConsole() |> ignore) | ||
let logger: ILogger = factory.CreateLogger("Program") | ||
let timespan = System.TimeSpan() | ||
let timeWasteString = "time waste" | ||
let result = "result" | ||
|
||
logger.LogWarning(sprintf "Foo {Wasted}\n{Result}", timeWasteString, result) |