Skip to content

Commit

Permalink
Fix detected analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jan 31, 2024
1 parent 93ab1b3 commit 32b7536
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/FSharp.Formatting.ApiDocs/GenerateModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ module internal SymbolReader =
if allLinesHaveSameColumn then
trimmed
else
$"<pre>{trimmed}</pre>"
$"<pre>%s{trimmed}</pre>"

let rec readXmlElementAsHtml
anyTagsOK
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Formatting.Literate/Evaluator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ module __FsiSettings =
StdErr = e.Result.Error.Merged }

let msg =
$"Evaluation failed and --strict is on\n file={file}\n asExpression={asExpression}, text={text}\n stdout={e.Result.Output.Merged}\n\ stderr={e.Result.Error.Merged}\n inner exception={e.InnerException}"
$"Evaluation failed and --strict is on\n file=%A{file}\n asExpression=%b{asExpression}, text=%s{text}\n stdout=%s{e.Result.Output.Merged}\n\ stderr=%s{e.Result.Error.Merged}\n inner exception=%A{e.InnerException}"

onError msg

Expand Down
22 changes: 11 additions & 11 deletions src/FSharp.Formatting.Literate/ParsePynb.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ module internal ParsePynb =
match this with
| Markdown source -> source
| Code code ->
let codeBlock = sprintf $"```{code.lang}\n{addLineEnd code.source}```"
let codeBlock = sprintf $"```%s{code.lang}\n%s{addLineEnd code.source}```"

match code.outputs with
| None -> codeBlock
| Some outputs ->
let outputsString = outputs |> String.concat "\n"
sprintf $"{codeBlock}\n{outputsString}"
sprintf $"%s{codeBlock}\n%s{outputsString}"

member this.ToFsx() =
match this with
| Markdown source -> $"(**\n{source}\n*)"
| Markdown source -> $"(**\n%s{source}\n*)"
| Code code when code.lang = "fsharp" ->
let codeBlock = addLineEnd code.source

match code.outputs with
| None -> codeBlock
| Some outputs ->
let outputsString = outputs |> String.concat "\n"
sprintf $"{codeBlock}\n(**\n{outputsString}\n*)"
| Code _ -> $"(**\n{this.ToMarkdown()}\n*)"
sprintf $"%s{codeBlock}\n(**\n%s{outputsString}\n*)"
| Code _ -> $"(**\n%s{this.ToMarkdown()}\n*)"

module Output =
let (|TextHtml|_|) (x: JsonElement) =
Expand All @@ -48,14 +48,14 @@ module internal ParsePynb =
|> Seq.map (fun x -> x.GetString().Replace("\r\n", "\n") |> addLineEnd)
|> String.concat ""

Some $"<p>{html}</p>"
Some $"<p>%s{html}</p>"
| _ -> None

let (|TextPlain|_|) (x: JsonElement) =
match x.TryGetProperty("text/plain") with
| true, text ->
let text = text.EnumerateArray() |> Seq.map (fun x -> x.GetString()) |> String.concat ""
Some $"""<table class="pre"><tbody><tr><td><pre><code>{text}</code></pre></td></tr></tbody></table>"""
Some $"""<table class="pre"><tbody><tr><td><pre><code>%s{text}</code></pre></td></tr></tbody></table>"""
| _ -> None

let (|DisplayData|_|) (x: JsonElement) =
Expand All @@ -65,7 +65,7 @@ module internal ParsePynb =
match x.TryGetProperty("data") with
| true, TextHtml html -> html
| true, TextPlain text -> text
| true, s -> failwith $"unknown output {s}"
| true, s -> failwith $"unknown output %A{s}"
| false, _ -> failwith "no data property"
|> Some
else
Expand All @@ -82,7 +82,7 @@ module internal ParsePynb =
| _ -> failwith "no text property"

Some
$"""<table class="pre"><tbody><tr><td><pre><code>{text}</code></pre></td></tr></tbody></table>"""
$"""<table class="pre"><tbody><tr><td><pre><code>%s{text}</code></pre></td></tr></tbody></table>"""
else
None
| _ -> failwith "no output_type property"
Expand All @@ -91,7 +91,7 @@ module internal ParsePynb =
match output with
| Stream stream -> stream
| DisplayData displayData -> displayData
| s -> failwith $"""unknown output {s.GetProperty("output_type").GetString()}"""
| s -> failwith $"""unknown output %s{s.GetProperty("output_type").GetString()}"""

let getSource (cell: JsonElement) =
let source =
Expand Down Expand Up @@ -152,7 +152,7 @@ module internal ParsePynb =
| _, Some _ -> failwith $"Markdown should not have outputs"
| source, None -> Markdown source
| "code" -> getCode cell
| _ -> failwith $"unknown cell type {cell_type}"
| _ -> failwith $"unknown cell type %s{cell_type}"

let pynbStringToMarkdown (ipynb: string) =
let json = JsonDocument.Parse(ipynb)
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Formatting.Markdown/MarkdownUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ module internal MarkdownUtils =

for (j, line) in List.indexed lines do
if i = 0 && j = 0 then
yield $"{n} " + line
yield $"%i{n} " + line
else
yield " " + line

Expand Down Expand Up @@ -329,7 +329,7 @@ module internal MarkdownUtils =
else
let tempRoot = "fsdocs-secret-temp-root"
// We can't be sure code is a single html element, we could get multiple elements.
let element = XElement.Parse($"<{tempRoot}>{code}</{tempRoot}>")
let element = XElement.Parse($"<%s{tempRoot}>%s{code}</%s{tempRoot}>")
// ends-with is XPath 2.0 only, https://stackoverflow.com/questions/1525299/xpath-and-xslt-2-0-for-net
let attributes =
match System.Xml.XPath.Extensions.XPathEvaluate(element, "//*/@*[contains(., '.md')]") with
Expand Down
12 changes: 6 additions & 6 deletions src/fsdocs-tool/BuildCommand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type internal DocContent
Some uri
with _ ->
printfn
$"Couldn't map markdown reference {markdownReference} that seemed to correspond to an input file"
$"Couldn't map markdown reference %s{markdownReference} that seemed to correspond to an input file"

None

Expand Down Expand Up @@ -352,7 +352,7 @@ type internal DocContent

let evaluateNotebook ipynbFile =
let args =
$"repl --run {ipynbFile} --default-kernel fsharp --exit-after-run --output-path {ipynbFile}"
$"repl --run %s{ipynbFile} --default-kernel fsharp --exit-after-run --output-path %s{ipynbFile}"

let psi =
ProcessStartInfo(
Expand All @@ -367,8 +367,8 @@ type internal DocContent
p.WaitForExit()
with _ ->
let msg =
$"Failed to evaluate notebook {ipynbFile} using dotnet-repl\n"
+ $"""try running "{args}" at the command line and inspect the error"""
$"Failed to evaluate notebook %s{ipynbFile} using dotnet-repl\n"
+ $"""try running "%s{args}" at the command line and inspect the error"""

failwith msg

Expand All @@ -392,7 +392,7 @@ type internal DocContent
psi.Arguments <- "tool list --global"
p.Start() |> ignore
let og = p.StandardOutput.ReadToEnd()
let output = $"{ol}\n{og}"
let output = $"%s{ol}\n%s{og}"

if not (output.Contains("dotnet-repl")) then
failwith failmsg
Expand All @@ -403,7 +403,7 @@ type internal DocContent

if evaluate then
checkDotnetReplInstall ()
printfn $" evaluating {inputFileFullPath} with dotnet-repl"
printfn $" evaluating %s{inputFileFullPath} with dotnet-repl"
evaluateNotebook inputFileFullPath


Expand Down
2 changes: 1 addition & 1 deletion src/fsdocs-tool/ProjectCracker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ module Crack =
projectFiles
|> List.filter (fun s ->
let isFSharpFormattingTestProject =
s.Contains $"FSharp.ApiDocs.Tests{Path.DirectorySeparatorChar}files"
s.Contains $"FSharp.ApiDocs.Tests%c{Path.DirectorySeparatorChar}files"
|| s.EndsWith("FSharp.Formatting.TestHelpers.fsproj", StringComparison.Ordinal)

if isFSharpFormattingTestProject then
Expand Down

0 comments on commit 32b7536

Please sign in to comment.