-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
154 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
### Credo Rules Styler Replaces | ||
|
||
If you're using Credo and Styler, **we recommend disabling these rules in `.credo.exs`** to save on unnecessary checks in CI. | ||
|
||
Disabling the rules means updating your `.credo.exs` depending on your configuration: | ||
|
||
- if you're using `checks: %{enabled: [...]}`, ensure none of the checks are listed in your enabled checks | ||
- if you're using `checks: %{disabled: [...]}`, copy/paste the snippet below into the list | ||
- if you're using `checks: [...]`, copy/paste the snippet below into the list and ensure none of the checks appear earlier in the list | ||
|
||
```elixir | ||
# Styler Rewrites | ||
# | ||
# The following rules are automatically rewritten by Styler and so disabled here to save time | ||
# Some of the rules have `priority: :high`, meaning Credo runs them unless we explicitly disable them | ||
# (removing them from this file wouldn't be enough, the `false` is required) | ||
# | ||
# Some rules have a comment before them explaining ways Styler deviates from the Credo rule. | ||
# | ||
# always expands `A.{B, C}` | ||
{Credo.Check.Consistency.MultiAliasImportRequireUse, false}, | ||
# including `case`, `fn` and `with` statements | ||
{Credo.Check.Consistency.ParameterPatternMatching, false}, | ||
# Styler implements this rule with a depth of 3 and minimum repetition of 2 | ||
{Credo.Check.Design.AliasUsage, false}, | ||
{Credo.Check.Readability.AliasOrder, false}, | ||
{Credo.Check.Readability.BlockPipe, false}, | ||
# goes further than formatter - fixes bad underscores, eg: `100_00` -> `10_000` | ||
{Credo.Check.Readability.LargeNumbers, false}, | ||
# adds `@moduledoc false` | ||
{Credo.Check.Readability.ModuleDoc, false}, | ||
{Credo.Check.Readability.MultiAlias, false}, | ||
{Credo.Check.Readability.OneArityFunctionInPipe, false}, | ||
# removes parens | ||
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, false}, | ||
{Credo.Check.Readability.PipeIntoAnonymousFunctions, false}, | ||
{Credo.Check.Readability.PreferImplicitTry, false}, | ||
{Credo.Check.Readability.SinglePipe, false}, | ||
# **potentially breaks compilation** - see **Troubleshooting** section below | ||
{Credo.Check.Readability.StrictModuleLayout, false}, | ||
{Credo.Check.Readability.StringSigils, false}, | ||
{Credo.Check.Readability.UnnecessaryAliasExpansion, false}, | ||
{Credo.Check.Readability.WithSingleClause, false}, | ||
{Credo.Check.Refactor.CaseTrivialMatches, false}, | ||
{Credo.Check.Refactor.CondStatements, false}, | ||
# in pipes only | ||
{Credo.Check.Refactor.FilterCount, false}, | ||
# in pipes only | ||
{Credo.Check.Refactor.MapInto, false}, | ||
# in pipes only | ||
{Credo.Check.Refactor.MapJoin, false}, | ||
{Credo.Check.Refactor.NegatedConditionsInUnless, false}, | ||
{Credo.Check.Refactor.NegatedConditionsWithElse, false}, | ||
# allows ecto's `from | ||
{Credo.Check.Refactor.PipeChainStart, false}, | ||
{Credo.Check.Refactor.RedundantWithClauseResult, false}, | ||
{Credo.Check.Refactor.UnlessWithElse, false}, | ||
{Credo.Check.Refactor.WithClauses, false}, | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
### Troubleshooting: Compilation broke due to Module Directive rearrangement | ||
|
||
Styler naively moves module attributes, which can break compilation. For now, the only fix is some elbow grease. | ||
|
||
#### Module Attribute dependency | ||
|
||
Another common compilation break on the first run is a `@moduledoc` that depended on another module attribute which | ||
was moved below it. | ||
|
||
For example, given the following broken code after an initial `mix format`: | ||
|
||
```elixir | ||
defmodule MyGreatLibrary do | ||
@moduledoc make_pretty_docs(@library_options) | ||
use OptionsMagic, my_opts: @library_options | ||
|
||
@library_options [ ... ] | ||
end | ||
``` | ||
|
||
You can fix the code by moving the static value outside of the module into a naked variable and then reference it in the module. (Note that `use` macros need an `unquote` wrapping the variable!) | ||
|
||
Yes, this is a thing you can do in a `.ex` file =) | ||
|
||
```elixir | ||
library_options = [ ... ] | ||
|
||
defmodule MyGreatLibrary do | ||
@moduledoc make_pretty_docs(library_options) | ||
use OptionsMagic, my_opts: unquote(library_options) | ||
|
||
@library_options library_options | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters