Prettyarrows

A mix format plugin that makes aligned columns pretty, especially for with clauses and Ecto schema fields.

Installation

Add prettyarrows to your dependencies in mix.exs:

def deps do
  [
    {:prettyarrows, "~> 0.1.0", only: :dev, runtime: false}
  ]
end

Then run:

mix deps.get

Usage

Add Prettyarrows to the :plugins list in your .formatter.exs:

[
  plugins: [Prettyarrows],
  inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

Now mix format will align with clause arrows and Ecto field types.

with clauses

Input:

with a_result <- a_func(),
     {:ok, b_result_with_a_longer_name} <- b_func(),
     c <- c_func() do
  {:ok, c}
end

Output (default, left-padded):

with                           a_result <- a_func(),
     {:ok, b_result_with_a_longer_name} <- b_func(),
                                      c <- c_func() do
  {:ok, c}
end

Right-pad the arrows instead:

[
  plugins: [Prettyarrows],
  with_padding: :right
]

Ecto fields

Input:

schema "users" do
  field :id, :uuid
  field :name, :string
  field :nowish, :datetime
  field :c, :enum
end

Output (default, without parentheses):

schema "users" do
  field :id,     :uuid
  field :name,   :string
  field :nowish, :datetime
  field :c,      :enum
end

Keep parentheses in the output:

[
  plugins: [Prettyarrows],
  ecto: [parens: true]
]

Configuration

Each formatter can be configured and enabled or disabled independently.

[
  plugins: [Prettyarrows],
  with_padding: :left,        # :left (default) or :right
  with: true,                 # enable/disable the with formatter
  ecto: [
    fields: [
      enabled: true,          # enable/disable the ecto fields formatter
      parens: false           # optional parentheses in ecto fields
    ]
  ]
]

Nested configuration is also supported:

[
  plugins: [Prettyarrows],
  prettyarrows: [
    with: [padding: :right, enabled: true],
    ecto: [enabled: false, parens: true]
  ]
]

License

MIT