View Source Styler

Styler is an AST-rewriting tool. Think of it as a combination of mix format and mix credo, except instead of telling you what's wrong, it just rewrites the code for you to fit our style rules. Hence, mix style!

Styler is configuration-free. Like mix format, it runs based on the inputs from .formatter.exs and has opinions rather than configuration.

mix-style

mix style

mix style is a 1-1 stand-in for mix format in all the normal use-cases. Run mix help style for help using it.

styler-and-comments

Styler and Comments...

Styler is currently unaware of comments, so you may find that it puts them in really odd spots after a rewrite.

If you find that a comment was put somewhere weird after using Styler, you'll just have to manually put it back where you want it after. Feel free to grumble about it in an Issue so that we can properly prioritize making this work better in the future.

current-styles

Current Styles

You can find the currently-enabled styles in the Mix.Tasks.Style module, inside of its @styles module attribute. Each Style's moduledoc will tell you more about what it rewrites.

credo-rules-styler-replaces

Credo Rules Styler Replaces

credo rulestyle that rewrites to suit
Credo.Check.Readability.AliasOrderStyler.Style.Aliases
Credo.Check.Readability.MultiAliasStyler.Style.Aliases
Credo.Check.Readability.UnnecessaryAliasExpansionStyler.Style.Aliases
Credo.Check.Readability.SinglePipeStyler.Style.Pipes
Credo.Check.Refactor.PipeChainStartStyler.Style.Pipes

writing-styles

Writing Styles

Write a new Style by implementing the Styler.Style behaviour. See its moduledoc for more.

where-is-sourceror

Where is Sourceror?

This work was inspired by earlier large-scale rewrites of our codebase that used the fantastic tool called Sourceror.

The initial implementation of Styler used Sourceror, but Sourceror's AST-embedding comment algorithm causes Styler to be too slow to use as a normal formatter. Still, we're grateful for the inspiration Sourceror provided and the changes to the Elixir AST APIs that it drove.

The AST-Zipper implementation in this project was derived mostly from Sourceror's implementation.