Current section
Files
Jump to
Current section
Files
pretty_arrows
README.md
README.md
# Pretty Arrows
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.2.4", only: [:dev, :test], 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]
]
```
Align more than the default two columns (field name and type):
```elixir
[
plugins: [PrettyArrows],
ecto: [columns: 3] # also aligns the options column
]
```
## 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
columns: 2 # how many columns to align (default: 2)
]
]
]
```
Nested configuration is also supported:
```elixir
[
plugins: [PrettyArrows],
prettyarrows: [
with: [padding: :right, enabled: true],
ecto: [enabled: false, parens: true]
]
]
```
## License
MIT