Skip to content

Commit

Permalink
Fix "--config" rejecting directories with a "."
Browse files Browse the repository at this point in the history
  • Loading branch information
tcallan committed Feb 24, 2020
1 parent 2f85788 commit 3ab681a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/Fantomas.Tests/FormatConfigJsonConfigurationFileTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,34 @@ let ``pointing to config in a subfolder should return parent config file as well
delete parentFile
delete childFolder

[<Test>]
let ``pointing to subfolder containing dot and trailing slash returns parent config file`` () =
let parentFile = mkConfig None FormatConfig.Default
let subDir = uniqueString() + ".dir"
mkConfigFromContent "Test.fs" (Some(subDir)) "" |> ignore
let dirSep = string Path.DirectorySeparatorChar
let childFolder = Path.GetDirectoryName(parentFile) + dirSep + subDir + dirSep
try
let paths = ConfigFile.findConfigurationFiles childFolder
paths == [parentFile]
finally
delete parentFile
delete childFolder

[<Test>]
let ``pointing to subfolder conntaining dot without trailing slash returns parent config file`` () =
let parentFile = mkConfig None FormatConfig.Default
let subDir = uniqueString() + ".dir"
mkConfigFromContent "Test.fs" (Some(subDir)) "" |> ignore
let dirSep = string Path.DirectorySeparatorChar
let childFolder = Path.GetDirectoryName(parentFile) + dirSep + subDir
try
let paths = ConfigFile.findConfigurationFiles childFolder
paths == [parentFile]
finally
delete parentFile
delete childFolder

[<Test>]
let ``simple config file parses valid option`` () =
let path = mkConfigFromJson None "{\"KeepNewlineAfter\":true}"
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas/ConfigFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let rec findConfigurationFiles fileOrFolder : string list =
|> List.map (fun fn -> Path.Combine(folderPath, fn))
|> List.filter (File.Exists)

if Path.GetExtension(fileOrFolder) = "" && Directory.Exists fileOrFolder then
if Directory.Exists fileOrFolder then
getParentFolders [] fileOrFolder
|> List.collect findConfigInFolder
elif File.Exists(fileOrFolder) then
Expand Down

0 comments on commit 3ab681a

Please sign in to comment.