Search code examples
haxe

Is there a code formatter tool for Haxe code?


Is there a Haxe code formatter, to beautify code?

Alternatively, if there is one that is made for other languages, but works well enough, it can also be accepted.


Solution

  • There's now a dedicated code formatter for Haxe called haxe-formatter. Compared to astyle, it actually properly understands all Haxe-specific constructs, including the latest Haxe 4 syntax and conditional compilation. You can install it from Haxelib and reformat your code from the command line:

    haxelib install formatter
    haxelib run formatter -s <source-directory>
    

    It's also integrated into the Haxe extension for VSCode out of the box:

    A very convenient way to use it is to enable "format on save" and "format on paste" in your settings, so your code is always formatted correctly:

    "[haxe]": {
        "editor.formatOnSave": true,
        "editor.formatOnPaste": true
    }
    

    But of course, you can also invoke the Format Document command manually (Shift+Alt+F).