CaseFormatter (pretty_arrows v0.3.0)

Copy Markdown View Source

A mix format plugin that aligns the -> arrows of one-line case clauses.

[
  plugins: [CaseFormatter]
]

Given two or more one-line clauses in a case block, the arrows are lined up in one column:

case result do
  {:ok, value} -> handle(value)
  :error -> handle_error()
end

becomes

case result do
  {:ok, value} -> handle(value)
  :error       -> handle_error()
end

Clauses whose body is on the following lines are left alone. This plugin has no :pretty_arrows options.

Summary

Functions

Returns the Mix.Tasks.Format features for this plugin. mix format calls this function, so you don't need to call it yourself.

Formats source and aligns the one-line case clause arrows.

Functions

features(opts)

Returns the Mix.Tasks.Format features for this plugin. mix format calls this function, so you don't need to call it yourself.

format(source, opts \\ [])

Formats source and aligns the one-line case clause arrows.

opts are passed to Code.format_string!/2. If source can't be parsed, the formatting step is skipped and the alignment runs on the text as it is.