Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "--config" rejecting directories with a "." #700

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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