Elixir Code Formatter
Format and beautify Elixir source code — operator/comma spacing, do/fn/end block-depth indentation, blank-line normalization around def/defmodule, and optional alphabetical sorting of alias/import/require/use groups, matching mix format conventions. Includes basic bracket and block-balance validation. Runs entirely in your browser.
Input
Used to flag overly long lines (mix format default is 98).
Output
| Issue |
|---|
| No data yet |
Guides
Paste unformatted Elixir source and get back code with consistent operator/comma spacing, do/fn/end block-depth indentation, and normalized blank lines — matching mix format conventions as closely as a browser-based formatter can. Strings, charlists, sigils (~r, ~D, …), heredocs, and comments are tokenized and left untouched; only the surrounding code gets reformatted. A quick validation pass flags unbalanced brackets and unmatched do/fn/end blocks. Everything runs locally in your browser.
How to use it
- Paste your Elixir source, or upload a
.ex/.exsfile. - Set Max Line Length to flag overly long lines (the
mix formatdefault is 98). - Turn on Sort & Group alias / import / require / use blocks to alphabetize each consecutive run of
alias/import/require/usestatements by module path — leave it off to keep your original order. - Check the Validation panel for any syntax issues, then copy or download the formatted result.
What it formats
- Spacing around binary operators (
+ - * / == != <= >= && || <> .. |> -> <-) and unary-/!/^/&, which stay tight against their operand. - Commas, semicolons, and the
key:shorthand used in keyword lists anddo:/else:blocks. %{...}maps and%MyStruct{...}struct literals, kept tight against the following brace.- Indentation by
do/fn↔endblock depth and bracket depth, withelse/rescue/catch/afterdedented back to their block's own level. - Blank-line normalization: collapses runs of blank lines to one, removes a stray blank right before
end/)/]/}, and inserts one before adef/defmodule/defprotocol/… declaration that follows other code (but not right after a block opener, or after its own@doc/@moduledoc/@spec).
Does it validate the code semantically?
No — this checks structure only: unbalanced ()[]{}, an unmatched do/fn without its end (or vice versa), and an unterminated heredoc. It won't catch an undefined function or a pattern-match that can never succeed. For real validation, use mix compile or mix format --check-formatted.
Is my code uploaded anywhere?
No. Tokenizing, spacing, and re-indenting all run locally in your browser; your Elixir source is never sent to a server.
Need to format a different language?
Use the Zig Language Formatter or the Lua Code Formatter for other hand-rolled, browser-side formatters.