Skip to content

elm-format formats Elm source code according to a standard set of rules based on the official Elm Style Guide

License

Notifications You must be signed in to change notification settings

jmandzik/elm-format

Repository files navigation

Build Status experimental latest version: 0.3.1-alpha

elm-format

elm-format is still in alpha. If you run into any problems, please report them.

The format produced by elm-format may change significantly before the 1.0.0 release. If this will cause problems for you, please refrain from using elm-format during the alpha- and beta-test periods.

elm-format formats Elm source code according to a standard set of rules. It is inspired by the popular gofmt.

The benefits of elm-format:

  • It makes code easier to write, because you never have to worry about minor formatting concerns while powering out new code.
  • It makes code easier to read, because there are no longer distracting minor stylistic differences between different code bases. As such, your brain can map more efficiently from source to mental model.
  • It makes code easier to maintain, because you can no longer have diffs related only to formatting; every diff necessarily involves a material change.
  • It saves your team time debating how to format things, because there is a standard tool that formats everything the same way.

Usage

elm-format Main.elm  # Format a single file
elm-format Main.elm --yes  # Overwrite the file without prompting
elm-format src/  # Format all *.elm files in a directory
elm-format --stdin  # Format input from stdin and write to stdout
elm-format --stdin --output Main.elm  # Format input from stdin and write to file
elm-format --help  # See other command line options

Installation (latest version: 0.3.1-alpha)

elm-format is still in alpha. If you run into any problems, please report them.

The format produced by elm-format may change significantly before the 1.0.0 release. If this will cause problems for you, please refrain from using elm-format during the alpha- and beta-test periods.

You will need to download the version appropriate for your OS, unzip it, and place elm-format or elm-format.exe (windows) on your PATH. Simpler installation options will be available once there is a stable release of elm-format.

If you need PGP signatures, see the releases page.

For Elm 0.17

(Using this version with Elm 0.16 files will migrate them to Elm 0.17 syntax.)

For Elm 0.16

Editor integration

If you can simplify or improve the installation instructions or add instructions for another editor, please make a pull request. The default behavior of elm-format-approved plugins is to format Elm files on save.

Integration with Atom

atom-elm-format supports elm-format. You can install elm-format using apm or the Atom package manager in Atom's settings.

atom-beautify 0.28.20 and above supports elm-format. You can install atom-beautify using apm or the Atom package manager in Atom's settings.

Integration with Light Table

  1. Makes sure elm-format is in your PATH
  2. Install the elm-light plugin using the Light Table plugin manager
  3. Add the following to your user keymap:
[:editor.elm "ctrl-s" :save :elm-format :elm.lint]

Integration with Vim

  1. Make sure elm-format is in your PATH.
  2. Install elm-vim (instructions)
  3. Add the following to your .vimrc file:
let g:elm_format_autosave = 1

Integration with Emacs

  1. Install elm-mode (instructions).
  2. Make sure elm-format is in your PATH.

That's all.

After the install C-c C-f (in elm-mode) runs the command elm-mode-format-buffer which is based on elm-format.

See also the respective section about elm-format at elm-mode

Integration with Sublime Text

Use the Elm Language Support package. Make sure elm-format is in your PATH.

Integration with Visual Studio Code

  1. Make sure elm-format is in your PATH.
  2. ext install elm to get the Elm tools for VSCode, which also know about elm-format.
  3. You don't need the "elm-format" listed in the VSCode package-available list.
  4. shift-alt-F or similar will call elm-format on the current file.

Development info

Building from source

git clone https://github.com/avh4/elm-format.git
cd elm-format
cabal sandbox init
cabal install --only-dependencies --enable-tests
cabal build
./dist/build/elm-format-0.17/elm-format-0.17 --help

Running tests

brew install shellcheck
cabal configure --enable-tests
./tests/run-tests.sh

About

elm-format formats Elm source code according to a standard set of rules based on the official Elm Style Guide

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Haskell 46.8%
  • Elm 26.8%
  • JavaScript 24.1%
  • Shell 2.1%
  • Batchfile 0.1%
  • Ruby 0.1%