erlalign (erlalign v0.1.6)

View Source

Erlang code formatter that applies column alignment on top of erlfmt output

ErlAlign mirrors ExAlign's functionality for Erlang source code, enabling readable column-aligned formatting similar to Go's gofmt

Summary

Functions

Align case/if arrows: Pattern -> Body

Align consecutive variable assignments: Var = value

Format Erlang source contents with column alignment. Options are merged from three sources with the following precedence

Load and merge configuration options from local config merged with global config

Load and merge configuration options from CLI, local config, and global config with correct precedence

Load global configuration from ~/.config/erlalign/.formatter.config. Returns a list of options or empty list if file not found or invalid.

Load local configuration from .formatter.config in the current directory. Returns a list of options or empty list if file not found or invalid.

Main CLI entry point. Parses arguments and runs the formatter Calls erlang:halt/1 with appropriate exit code

Set default value for trim_eol_ws option if not already set Default is true (trim trailing whitespace)

Trim trailing whitespace from all lines if trim_eol_ws option is true

Functions

align_case_arrows(Code)

Align case/if arrows: Pattern -> Body

align_comments(Code)

align_group(Lines, GetPosFun)

align_variable_assignments(Code)

Align consecutive variable assignments: Var = value

find_arrow_pos(Line)

find_balanced_close_debug(Content, Depth, InString)

find_protected_regions_debug(Line)

find_quote_close_debug(Content)

format(Contents)

Format Erlang source contents with column alignment. Options are merged from three sources with the following precedence:

  1. Opts argument (highest priority)
  2. Local config from .formatter.config in current directory
  3. Global config from ~/.config/erlalign/.formatter.config (lowest priority)

Supported options:

  • line_length (integer, default 98): Maximum line length for alignment
  • eol_at_eof (:add, :remove, or nil, default nil): Controls end-of-file newline handling
    • :add: add trailing newline if not present
    • :remove: remove all trailing newlines
    • nil: leave end-of-file newline unchanged
  • keep_separators (boolean, default false): Preserve separator lines
  • trim_eol_ws (boolean, default true): Trim trailing whitespace from lines

format(Contents, Opts)

handle_eol_at_eof(Result, Opts)

init(State)

-spec init(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.

load_config()

Load and merge configuration options from local config merged with global config

load_config(Opts)

Load and merge configuration options from CLI, local config, and global config with correct precedence

load_global_config()

Load global configuration from ~/.config/erlalign/.formatter.config. Returns a list of options or empty list if file not found or invalid.

load_local_config()

Load local configuration from .formatter.config in the current directory. Returns a list of options or empty list if file not found or invalid.

main(Args)

Main CLI entry point. Parses arguments and runs the formatter Calls erlang:halt/1 with appropriate exit code

set_default_trim_eol_ws(Opts)

Set default value for trim_eol_ws option if not already set Default is true (trim trailing whitespace)

trim_eol_whitespace(Code, Opts)

Trim trailing whitespace from all lines if trim_eol_ws option is true