Skip to content

Commit

Permalink
- Don't enforce any regex inside of braces
Browse files Browse the repository at this point in the history
- Don't care about unbalanced braces
  • Loading branch information
dawedawe committed Feb 16, 2024
1 parent ac234ce commit 7c84bc2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/FSharp.Analyzers/LoggingTemplateMissingValuesAnalyzer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let analyze (typedTree : FSharpImplementationFileContents) =
"Microsoft.Extensions.Logging.LoggerExtensions.LogWarning"
]

let pattern = @"(?<opening>{+)[a-zA-Z0-9_-]*(?<closing>}+)"
let pattern = @"(?<opening>{+)[^{}]*(?<closing>}+)"
let regex = Regex pattern

let walker =
Expand Down Expand Up @@ -86,10 +86,15 @@ let analyze (typedTree : FSharpImplementationFileContents) =

match logString with
| Some s ->
let matches = regex.Matches s
let matches =
regex.Matches s
|> Seq.filter (fun matchItem ->
matchItem.Groups["opening"].Value.Length = matchItem.Groups["closing"].Value.Length
)
|> Seq.toArray

let escapedMatches =
Seq.sumBy
Array.sumBy
(fun (matchItem : Match) ->
let opening = matchItem.Groups["opening"]
let closing = matchItem.Groups["closing"]
Expand All @@ -98,7 +103,7 @@ let analyze (typedTree : FSharpImplementationFileContents) =
)
matches

matches.Count - escapedMatches
matches.Length - escapedMatches
| None -> 0

if
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module M

open Microsoft.Extensions.Logging

let testlog () =
use factory = LoggerFactory.Create(fun b -> b.AddConsole() |> ignore)
let logger: ILogger = factory.CreateLogger("Program")

logger.LogDebug("Blah {xxx}} foo {yyy}", 23)
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 someString = "someString"
let someOtherString = "someOtherString"

logger.LogDebug("Blah {s_thing:l} foo {s_other_thing:l}", someString, someOtherString)

0 comments on commit 7c84bc2

Please sign in to comment.