diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000000..e35338e4a9 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1 @@ +image: mcr.microsoft.com/dotnet/sdk:5.0 \ No newline at end of file diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 37e6bfda47..6ccb5ba16f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,7 @@ +### 4.4.0-alpha-007 12/2020 + +* Fix Program.fs inside full path can lead to invalid AST. [#1337](https://github.com/fsprojects/fantomas/issues/1337) + ### 4.4.0-alpha-006 12/2020 * Fix Formatting of long parameter lists. [#657](https://github.com/fsprojects/fantomas/issues/657) diff --git a/src/Fantomas.CoreGlobalTool.Tests/Fantomas.CoreGlobalTool.Tests.fsproj b/src/Fantomas.CoreGlobalTool.Tests/Fantomas.CoreGlobalTool.Tests.fsproj index 5f13cd36a9..3f8c989333 100644 --- a/src/Fantomas.CoreGlobalTool.Tests/Fantomas.CoreGlobalTool.Tests.fsproj +++ b/src/Fantomas.CoreGlobalTool.Tests/Fantomas.CoreGlobalTool.Tests.fsproj @@ -4,7 +4,7 @@ net5.0 false false - 4.4.0-alpha-006 + 4.4.0-alpha-007 FS0988 FS0025 diff --git a/src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj b/src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj index 9c5233d9bd..6e93f60d76 100644 --- a/src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj +++ b/src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj @@ -4,7 +4,7 @@ net5.0 fantomas True - 4.4.0-alpha-006 + 4.4.0-alpha-007 fantomas-tool FS0025 diff --git a/src/Fantomas.Extras/Fantomas.Extras.fsproj b/src/Fantomas.Extras/Fantomas.Extras.fsproj index 65f86d1b49..1adb3439f4 100644 --- a/src/Fantomas.Extras/Fantomas.Extras.fsproj +++ b/src/Fantomas.Extras/Fantomas.Extras.fsproj @@ -2,7 +2,7 @@ netstandard2.0 - 4.4.0-alpha-006 + 4.4.0-alpha-007 Utility package for Fantomas FS0025 diff --git a/src/Fantomas.Tests/CodeFormatterTests.fs b/src/Fantomas.Tests/CodeFormatterTests.fs index 3a893840e7..55a4939194 100644 --- a/src/Fantomas.Tests/CodeFormatterTests.fs +++ b/src/Fantomas.Tests/CodeFormatterTests.fs @@ -31,3 +31,30 @@ let main argv _ = ) |> Async.RunSynchronously |> ignore + +[] +let ``sanitize filename if path with Program.fs`` () = + let fileName = @"d:\dev\bootcamp\src\Program.fs" + + let source = """ +open System +open Poker.Main + +[] +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 diff --git a/src/Fantomas.Tests/Fantomas.Tests.fsproj b/src/Fantomas.Tests/Fantomas.Tests.fsproj index 371c73b17e..6d3ea00548 100644 --- a/src/Fantomas.Tests/Fantomas.Tests.fsproj +++ b/src/Fantomas.Tests/Fantomas.Tests.fsproj @@ -1,6 +1,6 @@ - 4.4.0-alpha-006 + 4.4.0-alpha-007 FS0988 net5.0 FS0025 diff --git a/src/Fantomas/CodeFormatterImpl.fs b/src/Fantomas/CodeFormatterImpl.fs index 6caf30bf77..5a60726522 100644 --- a/src/Fantomas/CodeFormatterImpl.fs +++ b/src/Fantomas/CodeFormatterImpl.fs @@ -41,11 +41,14 @@ 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: string) = + let fileName = + file.Split([| '\\'; '/' |]) |> Array.last + if fileName = "Program.fs" then "tmp.fsx" else - fileName + file let createFormatContext fileName (source: SourceOrigin) = let (sourceText, sourceCode) = getSourceTextAndCode source diff --git a/src/Fantomas/Fantomas.fsproj b/src/Fantomas/Fantomas.fsproj index fbfa1960fc..b3e4cf3a6f 100644 --- a/src/Fantomas/Fantomas.fsproj +++ b/src/Fantomas/Fantomas.fsproj @@ -2,7 +2,7 @@ netstandard2.0 - 4.4.0-alpha-006 + 4.4.0-alpha-007 Source code formatter for F# FS0025