Dear reader, it is with great pride, that I announce that Fantomas, the F# formatting tool, has released its fourth major version!
This is the culmination of the work of over fourteen contributors and countless members of the F# community. It is a genuine pleasure to see this growth and we are grateful for everyone’s involvement.
The overarching theme of this release was improving Fantomas to a point that teams at G-Research can format code as part of the development process. There are two main key action points to achieve this: one, fix all the bugs that they encounter in their code base and two, allow for some stylistic configuration options.
You see, the folks at G-Research today format their code slightly differently from what the Microsoft style guide dictates. G-Research has been using their alternate style for many years now; and have even published their own style guide on GitHub. Therefore, some new settings were introduced so that Fantomas can support both style guides and additional preferences in the future.
Sample code to view difference between styles:
We introduced some new settings that allow you to control the maximum width of certain code constructs. For example: “How long do you want an array to be in one single line?” If you say: “Well, 30 characters seems reasonable” then Fantomas will format arrays in a multiline fashion the moment it gets longer than the 30 characters threshold.
Another thing we did was splitting up SpaceBeforeArgument to have more control over where you want a space and where you don’t. Maybe you prefer a space before `()` when defining a function but perhaps not when calling that function.
When it comes to formatting Elmish-inspired code, Fantomas usually dropped the ball. For some people, this prevented them from using Fantomas at all. The main problem here was that nested Elmish code would get all tangled up at the end and you could not really tell which element was closed off.
To solve this, we tried to come up with a better way to format Elmish code based on detecting Elmish-inspired code in the AST.
You can find our reasoning on GitHub and check out a comparison:
Another significant change is the move from our custom configuration file to .editorconfig.
Our command line tool now picks up configuration from nearby .editorconfig files.
The JSON format is no longer supported, and integration in all popular editors has been updated.
Pro tip: use our online tool to configure your Fantomas settings. Once you’ve modified any of the default settings, a button to copy and paste the configuration will become visible.
Another area which we knew could use some love was performance. Fantomas could format at an acceptable speed if your file size was small and innocent. Large files though, well…, not so acceptable.
So, prompted by some feedback from the community, we started benchmarking and profiling Fantomas.
We’re very happy with our current progress: when formatting a file of 3500 lines, we went from 50 seconds to 5 seconds.
This effort is ongoing, and we are excited to see how fast we can get Fantomas’ formatting speed to go.
On a personal note, I have ambitions to get more people involved in the project this year, both in using the tool and contributing to our repository. But I know from personal experience that contributing can be incredibly challenging.
So that is why I started a YouTube channel with some easy digestible “How To” videos. In these videos, I explain how Fantomas works internally and what my process is to solve bugs. “Give a Man a Fish, and You Feed Him for a Day. Teach a Man To Fish, and You Feed Him for a Lifetime”, am I right?
I really hope to encourage people to solve their own reported bugs.
In addition to the YouTube effort, I also tried to spread the message through online conferences. Inspired by my colleague Hannes Lowette, I submitted to numerous call-for-papers so I could try and talk about Fantomas. Against all odds, I was accepted to speak at JetBrains .NET Days, fsharpConf and .NETSummit. I wholeheartedly appreciate all these opportunities, and can’t thank all the organizers enough for having me.
But our story gets even crazier! A couple of months after fsharpConf, completely out of nowhere, someone created an extension to use Fantomas in Visual Studio. The user Asti single-handedly created this plugin after hearing my talk, and words cannot express how amazing this is.
This brings Fantomas to a whole new userbase and is truly a significant leap on the road to adoption.
There is still work to be done in Fantomas; call it a never-ending story 😉
We don’t have a strict roadmap so I might just list some items that pique my interest:
No commitments nor timings, though. Only time will tell.
As mentioned, this has been one hell of a release. Many people were involved, and I would like to thank everyone who contributed, everyone who reported a bug, the wonderful people from G-Research and anyone who stood by me in some way, shape, or form.
Get to know Axxes and our corporate culture!