New formatter haxelib library

(Alexander Blum) #1

Does your code look old?
Has your code lost its shininess?
Is your whitespace all over the place?
Do you use tabs and/or spaces for indentation?
Have you messed up your curlys?
Do you use empty lines?
Do you like it when format happens in your code?

Then why not try haxelib run formatter -s folderWithDustyOldCode? (*)

Out now: formatter - available at your local haxelib store.

Check out our low low prices!

For a limited(**) time only: free VSCode integration!

(*) use backups; diff tool recommended
(**) for very very broad values of limited

(Alexander Blum) #2

For anyone interested in seeing what the default built-in hxformat.json configuration file looks like, here it is: (note: dev version differs from 1.0.0 release)

(Valentin Lemière) #3

Seems there is already a good amount of configuration option :+1:

Something that would be really awesome is an online tool (or a vscode extension) similar to to create your own config easily.

(Alexander Blum) #4

Formatter has lots of options, but obviously we haven’t tested every combination of options, most unittests use built-in defaults, so there might be some side effects when configuring your personal code style.

A configuration tool would be really cool, e.g. it could be a HaxeUI based VSCode extension (maybe with multiple tabs for different types of configuration options), that has a split view showing a live preview of formatting results. All we need is a volunteer… :slight_smile:

For now we have auto-completion in VSCode through JSON schema.

(Alexander Blum) #5

For anyone not running VSCode, I have heard from someone using the command line version from within HaxeDevelop to format files on demand. I’m not using HaxeDevelop, so I don’t know how to set it up or how well you can integrate it with your workflow.
That might also work for other editors.

It helps to have NodeJS installed, since haxelib run formatter or neko <formatter>\run.n will try to run node run.js - the NodeJS version is a lot faster than the Neko version (a C++ version is only slightly faster compared to NodeJS).

(Jason O'neil) #6

Finally got a chance to use this - it’s amazing! Thanks so much, this was something I’ve learned to love in other languages that I really missed in Haxe.

(Alexander Blum) #7

The latest vshaxe extension (2.4.1) brings haxe-formatter 1.1.0 to VSCode which offers additional emptyLines settings and the ability to wrap method chains (and a few other changes).

If you have a hxformat.json containing custom wrapping rules, you will have to adjust them from e.g.:

  "wrapping": {
    "anonType": [{"conditions": [{"cond": "itemCount <= n", "value": 3}], "type": "noWrap"}]


  "wrapping": {
    "anonType": {
      "defaultWrap": "noWrap",
      "rules": [{"conditions": [{"cond": "itemCount <= n", "value": 3}], "type": "noWrap"}]

(Alexander Blum) #8

I have released haxe-formatter 1.1.2 yesterday (for VSCode users: it’s already included with vshaxe 2.4.4).
It brings a few bugfixes, e.g. wrapping with “keep” should now work as intended, and indentation logic should give nicer results for cases where left curly is on “next” line instead of “same”.

I also added a small section to explaining how to start using formatter in your projects.