-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Support check-style flag on fantomas-tool #642
Comments
Hello @lpedrosa, this sounds like a good idea but I'm not sure I want this in Fantomas just yet. I would also like to see this in practice first to get a good feel of how this would work out in on a real project. So my suggestion here it the following: I hope you can understand my reasoning here, let me know what you think. |
That makes sense, thanks for the detailed explanation!
I am not very familiar with FAKE but it's on my list of things to pick up, since most of the F# projects seem to use it. Just to clarify some things before I begin:
|
With POC in FAKE I mean create a FAKE target that does the format check you have in mind. See https://github.com/fsprojects/fantomas/blob/master/fake-sample/script.fsx for example. Build agents can then call |
Hey @nojaf, I apologise for the delay. Here an example project: https://github.com/lpedrosa/fantomas-check Most of the logic is in the Let me know what you think. |
Hey @lpedrosa , this looks like a nice sample. Thanks! I'll try it out in my own projects later this week. |
@lpedrosa I've added the sample you provide to one of my projects, https://github.com/nojaf/trivia-tool/blob/master/build.fsx#L70 I suggest that I play around with it for some time and see how it goes. |
Hi @nojaf, I will have a look!
I'm not sure I follow what you meant here. Are you suggesting to do this check before calling the |
Hey @lpedrosa , I was thinking of replacing CodeFormatter.FormatDocumentAsync by formatFileAsync and do some sort of check based on doing some sort of check based on the timestamp to quickly find out whether any file did change. The replacing part still seems like a good idea, the timestamp check thing not. |
I think I got what you are saying. If I am not mistaken, the In that case, you are right pointing out that the
Is that a good analysis of your proposal? |
I was also wondering: is there a way to make the abstraction returned by the The
|
@lpedrosa it would be great if we check that the formatted output is valid AST. I'm in favour of replacing the current cli to have this behaviour. That might resolve my initial concert that Fantomas doesn't always product valid AST after format. To move forward:
@lpedrosa do you want to take the lead on this in a PR? I'm happy to help out where needed. |
Sound great, I'll keep you posted with any questions I might have. One final question:
Do you mean that if the |
Yes, so in case the user tries I would still return exitcode 0 if this happens as this isn't the user's fault. |
Thank you for looking into this. I am investigating adding a |
Hey @VivekRajagopal , if you want a solution today you can check out @lpedrosa his sample FAKE script. I'm using it myself here. Otherwise you'll need to wait until we have an implementation for |
* Uses FakeHelper's format family functions which classify the format result i.e. changed/unchanged/error, in preparation for a --check command (fsprojects#642)
* Uses FakeHelper's format family functions which classify the format result i.e. changed/unchanged/error, in preparation for a --check command (fsprojects#642)
* adapt process to use formatFileAsync API * CoreGlobalTool checks if formatted code is valid * Uses FakeHelper's format family functions which classify the format result i.e. changed/unchanged/error, in preparation for a --check command (#642) * fix bug where stdin would not accept cat files * update --stdin flag docs * address code review concerns * remove need for temp files in FormatResult * Updated month in release notes * Initial CLI check functionality draft * Supports checking both files and folders * Always reports changes to stdout * make check code faster * previously it was blocking for every element of the sequence and that was delaying the output massivelly * now it should be pretty responsive * update docs * add test CLI test project * Refactor and test check functionality * Added CoreGlobalTool.Test project * Test specific CoreGlobalTool functionality * Separated --check command logic into a separate module * Removed src folder from solution * Removed nunitlite * Refactored checkCode to FAKEHelpers Co-authored-by: Florian Verdonck <[email protected]>
@lpedrosa you can test this with https://www.nuget.org/packages/Fantomas/3.3.0-beta-002 |
I've tested it out the CLI. I only noticed now that I missed something on the return values, which will not match the docs or the usage string:
Right now it's always exiting with 99 if the files have no error but need formatting. Should be a question of swapping it around and fixing the tests. Do you want me to do it @nojaf (in another PR) or do you want to use your magical "master push powers 🎩"? I have also created a branch on my
Can you double check if that's happening with you @nojaf? Could be something with my lock files. |
This is caused by FSharp.Compiler.Service version mismatch. You need to pin version of |
That seemed to fix it, when I tried locally. It does seem to resolve to 34.1 on the lock file, example when we don't pin the version. Is this a common gotcha with how fake dependencies are pulled by paket? Ideally, the user wouldn't need to know about the compiler service at all. |
Closing this issue as the original functionality was implemented. |
Summary
Add CLI support for check-style flag much like other code formatters out there. This would allow fantomas to run in a CI environment and check if the codebase is consistently formatted.
Description
In a team setting, it is desirable to have a consistent codebase. Many other languages have formatters available, here are some examples:
All of these formatters have a way to specify that we are only interested in understanding if any of the files scanned requires formatting:
--check
flag, which exits with a code other than 0, if any of the files requires formatting.-l
flag, which outputs only the filenames of the files that require formatting.Both these approaches can be used in a CI pipeline step, in order to keep formatting consistency in a codebase.
I believe the
FakeHelpers
module provides a similar task if you are using FAKE.Would it be possible to bring some of this logic to the CLI?
Proposal
Consider a simple program with a folder structure:
Assuming we forgot to run fantomas on our project, when we run it with the
--check
flag:The exit code could then be checked by any CI scripts and fail the build
I am available to help with this, if you are interested.
The text was updated successfully, but these errors were encountered: