Packages

A mix format plugin for aligning pretty columns in with clauses and Ecto fields

Retired package: Renamed - Renamed to pretty_arrows

Current section

Files

Jump to
prettyarrows README.md
Raw

README.md

# 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`:

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

Then run:

```sh
mix deps.get
```

## Usage

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

```elixir
[
  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:

```elixir
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):

```elixir
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:

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

### Ecto fields

Input:

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

Output (default, without parentheses):

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

Keep parentheses in the output:

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

## Configuration

Each formatter can be configured and enabled or disabled independently.

```elixir
[
  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:

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

## License

MIT