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

"fantomas --recurse" creates a "--recurse" directory #2854

Closed
witoldsz opened this issue Apr 20, 2023 · 11 comments · Fixed by #3024
Closed

"fantomas --recurse" creates a "--recurse" directory #2854

witoldsz opened this issue Apr 20, 2023 · 11 comments · Fixed by #3024

Comments

@witoldsz
Copy link

Just updated from fantomas-tool 4.7.9 to fantomas 6.0.1 and it creates --recurse directories in my modules.

Steps to reproduce:

witoldsz@678db1ca1a61:/app/modules/event-logger2$ ls
bin  event-logger2.sln	main  Makefile	test  VERSION  w3module.yaml
witoldsz@678db1ca1a61:/app/modules/event-logger2$ dotnet fantomas --recurse .
                                                             
  Formatted │ 0 │ Ignored │ 6 │ Unchanged │ 8 │ Errored │ 0  
                                                             
witoldsz@678db1ca1a61:/app/modules/event-logger2$ ls
bin  event-logger2.sln	main  Makefile	--recurse  test  VERSION  w3module.yaml
witoldsz@678db1ca1a61:/app/modules/event-logger2$ 

As you can see, the --recurse directory appeared.

I can see, the fantomas 6.x does not require --recurse anymore, but my project upgrading to fantomas 6 is in progress and the --recurse flag is still required by other modules (using older fantomas version) and there is one build script for them all.

@nojaf
Copy link
Contributor

nojaf commented Apr 20, 2023

Hello,

Upgrading from version 4.7.9 to 6.0.1 entails two major version bumps, which may introduce breaking changes. Please be aware of this when making the update.

It's worth noting that if you pass a non-existent folder when multiple folders are being passed, the folder will be created as expected.

Mixing versions in your setup seems rather specific on how you choose to do things. You can detect the current version using dotnet fantomas --version and adjust your build script accordingly.

@witoldsz
Copy link
Author

OK, so I was fooled by official documentation at https://fsprojects.github.io/fantomas/docs/end-users/GettingStarted.html

USAGE: dotnet fantomas [--help] [--recurse] [--force] [--profile] [--fsi ] [--stdin] [--stdout] [--out ] [--check] [--daemon] [--version] []

showing the --recurse is a valid flag. I can see the tool does not show it anymore.

On the other side, I must admit this is very strange to identify the --recurse configuration flag as a directory name (even if it is not a valid flag) and also it is very strange to default to create any non-existing file or directory as a new directory.

Thanks for looking into my case!

@witoldsz
Copy link
Author

P.S.
It was tricky to remove that directory:

witoldsz@678db1ca1a61:/app/modules/event-logger2$ rmdir --recurse
rmdir: unrecognized option '--recurse'
Try 'rmdir --help' for more information.
witoldsz@678db1ca1a61:/app/modules/event-logger2$ rmdir -- --recurse

It is expected to treat any --something as a flag. Maybe fantomas could follow the rule?

@nojaf
Copy link
Contributor

nojaf commented Apr 20, 2023

GettingStarted.html was out of date indeed, I raised #2857

@witoldsz
Copy link
Author

For whomever it may be useful, my Makefile script works this around like this:

# TODO: upgrade fantomas everywhere and remove this workaround
FANTOMAS = dotnet fantomas `dotnet fantomas --version |grep -q v4.7 && echo --recurse`

check-format: tool-restore
	$(FANTOMAS) --check .

format: tool-restore
	$(FANTOMAS) .

[...]

@nojaf nojaf closed this as completed Jun 15, 2023
stroborobo added a commit to stroborobo/ionide-vscode-fsharp that referenced this issue Aug 28, 2023
TheAngryByrd pushed a commit to ionide/ionide-vscode-fsharp that referenced this issue Sep 6, 2023
* git: sync .fs eol with editorconfig

* git: apply renormalization to fix old inconsistencies

* build: remove `-r` from fantomas, arg was removed

creates an empty dir now...

ref: fsprojects/fantomas#2854

* dotnet global.json: enable rollForward latestFeature

Also update MSBuild.StructuredLogger, since dotnet 7.0.4 (sdk 7.0.202)
shipped with an a bump in the binlog version. Fake uses binlog as a
response from the dotnet process and crashed after using a newer sdk.

* CONTRIBUTING.md: update dotnet version and link

* omnisharp: set solution name, doesnt select default anymore
@MangelMaxime
Copy link

Hello, I often makes mistakes when invoking fantomas and because of that it creates empty directories.

It's worth noting that if you pass a non-existent folder when multiple folders are being passed, the folder will be created as expected.

Why is the expected behaviour to create an empty directory?

If I provide a single non existing directory then it reports it as missing which helps diagnostic the problem.

CleanShot 2023-12-21 at 10 49 13@2x

To me it feels strange to me that a formatting tool create additional files and not just consume only existing files.

@nojaf
Copy link
Contributor

nojaf commented Dec 21, 2023

You could format a directory and output it into a different directory.
If that destination directory does not exist we create it.
Because the source and destination are the same that happens.

@MangelMaxime
Copy link

Sorry, I don't understand do you have a command example?

Looking at the help message:

USAGE: dotnet fantomas [--help] [--force] [--profile] [--out <string>] [--check] [--daemon] [--version] [--verbosity <string>] [<string>...]

INPUT:

    <string>...           Input paths: can be multiple folders or files with *.fs,*.fsi,*.fsx,*.ml,*.mli extension.

OPTIONS:

    --force               Print the output even if it is not valid F# code. For debugging purposes only.
    --profile             Print performance profiling information.
    --out <string>        Give a valid path for files/folders. Files should have .fs, .fsx, .fsi, .ml or .mli extension only. Multiple files/folders are not supported.
    --check               Don't format files, just check if they have changed. Exits with 0 if it's formatted correctly, with 1 if some files need formatting and 99 if there was an
                          internal error
    --daemon              Daemon mode, launches an LSP-like server to can be used by editor tooling.
    --version             Displays the version of Fantomas
    --verbosity, -v <string>
                          Set the verbosity level. Allowed values are n[ormal] and d[etailed].
    --help                display this list of options.

It seems that if I do dotnet fantomas dir1 dir2 then both dir1 dir2 refers to <string>... which is the input paths arguments.

I also tried to use the --out option as I was thinking this is what you are referring to when speaking of a different directory but I was not able to make it works.

dotnet fantomas src --out fantomas fails with

➜  Glutinum.Converter git:(main) ✗ dotnet fantomas --out fantomas src      
                                                              
  Formatted │ 0 │ Ignored │ 0 │ Unchanged │ 0 │ Errored │ 30  
                                                              
Failed to format file: src/Glutinum.Converter/Utils/Keywords.fs
Failed to format file: src/Glutinum.Converter/Utils/Naming.fs
Failed to format file: src/Glutinum.Converter/Utils/String.fs
Failed to format file: src/Glutinum.Converter/Reader/TypeParameters.fs
Failed to format file: src/Glutinum.Converter/Reader/ClassDeclaration.fs
Failed to format file: src/Glutinum.Converter/Reader/Types.fs
Failed to format file: src/Glutinum.Converter/Reader/ModuleDeclaration.fs
Failed to format file: src/Glutinum.Converter/Reader/TypeNode.fs
Failed to format file: src/Glutinum.Converter/Reader/FunctionDeclaration.fs
...

Even if dotnet fantomas src works.

@nojaf
Copy link
Contributor

nojaf commented Dec 21, 2023

I really don't quite remember how it works. This seems to somewhat works for me: dotnet fantomas .\Style\ --out Foobar. Folder Foobar was created and contains the formatted files.
However there is something weird with the output file name.

@dawedawe
Copy link
Member

See 3024 for a possible fix.

@MangelMaxime
Copy link

I really don't quite remember how it works. This seems to somewhat works for me: dotnet fantomas .\Style\ --out Foobar. Folder Foobar was created and contains the formatted files.
However there is something weird with the output file name.

Ok perhaps, there is something strange in my project

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.

4 participants