elm-format
formats Elm source code
according to a standard set of rules based on the official Elm Style Guide.
It is inspired by the popular gofmt.
The benefits of elm-format
:
elm-format . # Format all *.elm files in the current directory
elm-format Main.elm # Format a single file
elm-format Main.elm --yes # Overwrite the file without prompting
elm-format src/ Main.elm # Format the listed files and directories
elm-format --help # See other command line options
To install elm-format
:
npm install -g elm-format
or download the version appropriate for your OS from the release page,
unzip it,
and place elm-format
or elm-format.exe
(windows) on your PATH
.
You must run elm-format
from the directory that contains your elm.json
(for Elm 0.19) or elm-package.json
(for Elm 0.18),
or else you must pass the appropriate --elm-version=0.19
/--elm-version=0.18
command line argument.
Find your editor in the table below. The recommended plugin for each editor is indicated with :trophy: (trophy emoji).
Editor | Plugin | Installation | Formatting | Format on save | Configuration | Error handling |
---|---|---|---|---|---|---|
Atom | :trophy: atom-elm-format | :white_check_mark: 2 steps | :white_check_mark: | :white_check_mark: | :white_check_mark: | :warning: no installation instructions |
atom-beautify | :warning: 3 steps | :white_check_mark: | :warning: requires configuration | :white_check_mark: | :white_check_mark: | |
Light Table | :trophy: elm-light | :warning: 3 steps | :white_check_mark: | :warning: requires configuration | :white_check_mark: | :warning: no installation instructions |
Vim | :trophy: elm-vim | :x: 6 steps | :white_check_mark: | ⚠️ requires configuration | :white_check_mark: | :x: no error message |
Emacs | :trophy: elm-mode | :x: 4 steps | :white_check_mark: | :warning: requires configuration | :white_check_mark: | :warning: no installation instructions |
Visual Studio Code | :trophy: Elm Tooling | :warning: 3 steps | :white_check_mark: | :warning: requires configuration | :white_check_mark: | :x: uninformative error message |
Sublime Text | :trophy: Elm Language Support | :white_check_mark: 2 steps | ❔ TBD | :white_check_mark: | ❔ TBD | ❔ TBD |
JetBrains (WebStorm, etc) | :trophy: intellij-elm | :warning: 4 steps | :white_check_mark: | :warning: requires configuration | :warning: requires configuration | ❔ TBD |
TextMate | :trophy: Elm.tmbundle | :white_check_mark: 2 steps | ❔ TBD | ❔ TBD | ❔ TBD | ❔ TBD |
These tools also integrate with elm-format:
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.
Install atom-elm-format
apm install elm-format
or use the Atom package manager in Atom's settings
Install elm-format
Install atom-beautify
apm install atom-beautify
or use the Atom package manager in Atom's settings
Use ^⌥B
(CTRL-ALT-B
) to format a file
[:editor.elm "ctrl-s" :save :elm-format :elm.lint]
Install elm-format
If your Emacs has package.el
(which is automatically the case for Emacs >= 24), you can install elm-mode
from the package in MELPA:
Ensure that you have added the MELPA source in your ~/.emacs.d/init.el
:
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
Install elm-mode (official instructions): Use M-x list-packages
and choose elm-mode
.
Add the following to your ~/.emacs.d/init.el
:
(add-hook 'elm-mode-hook 'elm-format-on-save-mode)
If you are an advanced vim user and already have a preferred vim plugin installation method, you may prefer to refer to the official elm-vim installation instructions. The instructions below are for those who need a step-by-step walkthrough of how to get the plugin set up.
Install elm-format
Install vim-plug (official instructions) NOTE: if you are using neovim, you will need to refer to the official instructions.
Download vim-plug:
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Make sure ~/.vimrc
exists and has a section like this:
call plug#begin('~/.vim/plugged')
" ... any active plugins
call plug#end()
Install elm-vim (official instructions)
Plug 'elmcast/elm-vim'
to the plug#begin
plugin section in your ~/.vimrc
vim
and run :PlugInstall
Add the following to your ~/.vimrc
:
let g:elm_format_autosave = 1
Configure the extension to format on save:
settings.json
file (instructions).settings.json
:"[elm]": {
"editor.formatOnSave": true
},
This is for WebStorm and other JetBrains IDEs like IntelliJ and PyCharm.
In IntelliJ, open Settings -> Languages & Frameworks -> Elm
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Use the instructions below to get started.
More detailed information is available in ./dev/Documentation/
.
# check out the repo
git clone https://github.com/avh4/elm-format.git
cd elm-format
# initial setup
ghcup install ghc 9.4.4
ghcup set ghc 9.4.4
cabal install hpack
# build
dev/build.sh -- build
# run the built elm-format
./_build/bin/elm-format/O0/elm-format
See dev/Documentation
for more contributor and build command documentation.