ExAlign (exalign v0.1.4)
Copy MarkdownA Mix formatter plugin that column-aligns Elixir code, similar to how
Go's gofmt aligns struct fields and variable groups.
Patterns aligned
- Keyword list entries -
key: valuealigns after the colon - Variable assignments -
var = valuealigns the= - Map arrow entries -
key => valuealigns the=> - Module attributes -
@attr valuealigns the value
Usage
Add to your project's .formatter.exs:
[
plugins: [ExAlign],
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]And add exalign to your mix.exs dependencies.
Global configuration
ExAlign reads default option values from ~/.config/exalign/.formatter.exs
when that file exists. The file must evaluate to a keyword list containing any
ExAlign-recognised keys (:line_length, :wrap_short_lines, :wrap_with).
Options found in the project-local .formatter.exs always take precedence
over the global file.
Example ~/.config/exalign/.formatter.exs:
[
line_length: 120,
wrap_short_lines: true,
wrap_with: :backslash
]
Summary
Functions
Formats the given Elixir source contents string, applying column alignment
on top of the standard Code.format_string! pass.
Returns the ExAlign options loaded from the global config file
~/.config/exalign/.formatter.exs, or an empty list if the file does not
exist or cannot be evaluated.
Functions
Formats the given Elixir source contents string, applying column alignment
on top of the standard Code.format_string! pass.
opts may include any standard formatter options plus the ExAlign-specific
keys :wrap_short_lines, :wrap_with, and :line_length.
Returns the ExAlign options loaded from the global config file
~/.config/exalign/.formatter.exs, or an empty list if the file does not
exist or cannot be evaluated.