View Source Styler.Style.ModuleDirectives (Styler v1.0.0-rc.0)
Styles up module directives!
This Style will expand multi-aliases/requires/imports/use and sort the directive within its groups (except use
s, which cannot be sorted)
It also adds a blank line after each directive group.
Credo rules
Rewrites for the following Credo rules:
Credo.Check.Consistency.MultiAliasImportRequireUse
(force expansion)Credo.Check.Readability.AliasOrder
(we sort__MODULE__
, which credo doesn't)Credo.Check.Readability.ModuleDoc
(adds@moduledoc false
if missing. includes*.exs
files)Credo.Check.Readability.MultiAlias
Credo.Check.Readability.StrictModuleLayout
(see section below for details)Credo.Check.Readability.UnnecessaryAliasExpansion
Credo.Check.Design.AliasUsage
Breakages
This can break your code.
Strict Layout
Modules directives are sorted into the following order:
@shortdoc
@moduledoc
@behaviour
use
import
alias
require
- everything else (unchanged)
If any of the sorted directives had a dependency on code that is now below it, your code will fail to compile after being styled.
For instance, the following will be broken because the module attribute definition will
be moved below the use
clause, meaning @pi
is undefined when invoked.
# before
defmodule Approximation do
@pi 3.14
use Math, pi: @pi
end
# after
defmodule Approximation do
@moduledoc false
use Math, pi: @pi
@pi 3.14
end
For now, it's up to you to come up with a fix for this issue. Sorry!
Strict Layout: interwoven conflicting aliases
Ideally no one writes code like this as it's hard for our human brains to notice the context switching! Still, it's a possible source of breakages in Styler.
alias Foo.Bar Bar.Baz.bop()
alias Baz.Bar Bar.Baz.bop()
# becomes
alias Baz.Bar alias Baz.Bar.Baz alias Foo.Bar Baz.bop() # was Foo.Bar.Baz, is now Baz.Bar.Baz Baz.bop()
Summary
Functions
Callback implementation for Styler.Style.run/2
.
Functions
Callback implementation for Styler.Style.run/2
.