Skip to content

Commit

Permalink
Take the full path into account when sanitizing file name. Fixes fspr…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Dec 25, 2020
1 parent 294495d commit a7bba90
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/Fantomas.Tests/CodeFormatterTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,30 @@ let main argv _ =
)
|> Async.RunSynchronously
|> ignore

[<Test>]
let ``sanitize filename if path with Program.fs`` () =
let fileName = @"d:\dev\bootcamp\src\Program.fs"

let source = """
open System
open Poker.Main
[<EntryPoint>]
let main _ =
processInput Console.In Console.Out
0
"""

let parsingOptions =
FakeHelpers.createParsingOptionsFromFile fileName

CodeFormatter.FormatDocumentAsync(
fileName,
SourceOrigin.SourceString source,
config,
parsingOptions,
sharedChecker.Value
)
|> Async.RunSynchronously
|> ignore
6 changes: 4 additions & 2 deletions src/Fantomas/CodeFormatterImpl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ type FormatContext =
SourceText: ISourceText }

// Some file names have a special meaning for the F# compiler and the AST cannot be parsed.
let safeFileName fileName =
let safeFileName file =
let fileName = Path.GetFileName(file)

if fileName = "Program.fs" then
"tmp.fsx"
else
fileName
file

let createFormatContext fileName (source: SourceOrigin) =
let (sourceText, sourceCode) = getSourceTextAndCode source
Expand Down

0 comments on commit a7bba90

Please sign in to comment.