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

Problem with --config and directory names containing "." #694

Closed
tcallan opened this issue Feb 20, 2020 · 1 comment · Fixed by #700
Closed

Problem with --config and directory names containing "." #694

tcallan opened this issue Feb 20, 2020 · 1 comment · Fixed by #700

Comments

@tcallan
Copy link
Contributor

tcallan commented Feb 20, 2020

$ fantomas --version                            
Fantomas v3.2.0

Given a project structure like the following:

$ tree
.
├── Code.Dir
│   └── Program.fs
└── fantomas-config.json

This works correctly and applies settings from fantomas-config.json:

$ fantomas --config Code.Dir/ Code.Dir/Program.fs
Code.Dir/Program.fs has been written.

This reports an error and ignores fantomas-config.json:

$ fantomas --config Code.Dir Code.Dir/Program.fs 
Couldn't process one or more Fantomas configuration files, falling back to the default configuration
System.Exception: No configuration files were found for Code.Dir
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1637.Invoke(String message) in E:\A\_work\130\s\src\fsharp\FSharp.Core\printf.fs:line 1637
   at Fantomas.CodeFormatterImpl.readConfiguration(String fileOrFolder) in C:\Users\nojaf\Projects\fantomas\src\Fantomas\CodeFormatterImpl.fs:line 679
Code.Dir/Program.fs has been written.

Note the lack of a trailing / on Code.Dir in the second example. I've reproduced this behavior on both Linux and Windows 10.

I believe the problem is the following line:

if Path.GetExtension(fileOrFolder) = "" && Directory.Exists fileOrFolder then

Microsoft (R) F# Interactive version 10.7.0.0 for F# 4.7
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> open System.IO;;
> Path.GetExtension("Code.Dir/");;
val it : string = ""

> Path.GetExtension("Code.Dir");;
val it : string = ".Dir"
@nojaf
Copy link
Contributor

nojaf commented Feb 21, 2020

Hey @tcallan, thanks for reporting this problem.
I know this is probably not the answer your looking for but would you be up for it to fix this yourself in a PR 😅?
There are not that many active contributors and you don't really need a lot of knowledge of the internals of Fantomas to solve this.

If you want to tackle this, you can start by writing a failing test in FormatConfigJsonConfigurationFileTests.fs and indeed apply a fix in ConfigFile.fs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants