Quokka is an Elixir formatter plugin that's combination of mix format
and mix credo
, except instead of telling
you what's wrong, it just rewrites the code for you to fit its style rules.
Quokka is a fork of Styler that checks the credo config to determine which rules to rewrite.
- auto-fixes many credo rules, meaning you can turn them off to speed credo up
- keeps a strict module layout
- alphabetizes module directives
- extracts repeated aliases
- makes your pipe chains pretty as can be
- pipes and unpipes function calls based on the number of calls
- optimizes standard library calls (
a |> Enum.map(m) |> Enum.into(Map.new)
=>Map.new(a, m)
)
- replaces strings with sigils when the string has many escaped quotes
- reorders configuration in config files
- expands multi-alias/import statements
- enforces consistent function call parentheses
- ensures consistent spacing around operators
- formats documentation comments
- removes unnecessary parentheses
- simplifies boolean expressions
- enforces consistent module attribute usage
- formats and organizes typespecs
- ... and many more style improvements
See our Rewrites documentation on hexdocs
Add :quokka
as a dependency to your project's mix.exs
:
def deps do
[
{:quokka, "~> 0.1", only: [:dev, :test], runtime: false},
]
end
Then add Quokka
as a plugin to your .formatter.exs
file
[
plugins: [Quokka]
]
And that's it! Now when you run mix format
you'll also get the benefits of Quokka's Stylish Stylings.
Speed: Expect the first run to take some time as Quokka
rewrites violations of styles and bottlenecks on disk I/O. Subsequent formats formats won't take noticeably more time.
Quokka can be configured in your .formatter.exs
file
[
plugins: [Quokka],
quokka: [
alias_lifting_exclude: [...],
reorder_configs: true | false
]
]
Quokka has several configuration options:
:alias_lifting_exclude
, which accepts a list of atoms to not lift. See the Module Directive documentation for more:reorder_configs
, which controls whether or not the configs in yourconfig/*.exs
files are alphabetized. This is true by default.
In some cases, this can introduce bugs. It goes without saying, but look over your changes before committing to main :)
Some ways Quokka can change your program:
with
statement rewrites- config file sorting
- and likely other ways. stay safe out there!
Quokka is licensed under the Apache 2.0 license. See the LICENSE file for more details.