-
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
6 changed files
with
109 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Module Directives (`use`, `import`, `alias`, `require`, ...) |
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,32 @@ | ||
# Pipe Chain Styles | ||
|
||
|
||
## Pipe Start | ||
|
||
- raw value | ||
- blocks are extracted to variables | ||
- ecto's `from` is allowed | ||
|
||
## Piped function rewrites | ||
|
||
- add parens to function calls `|> fun |>` => `|> fun() |>` | ||
- remove unnecessary `then/2`: `|> then(&f(&1, ...))` -> `|> f(...)` | ||
- add `then` when defining anon funs in pipe `|> (& &1).() |>` => `|> |> then(& &1) |>` | ||
|
||
## Piped function optimizations | ||
|
||
- tries to fit everything on one line | ||
- `lhs |> Enum.reverse() |> Enum.concat(enum)` => `lhs |> Enum.reverse(enum)` (also Kernel.++) | ||
- `lhs |> Enum.filter(filterer) |> Enum.count()` => `lhs |> Enum.count(count)` | ||
- `lhs |> Enum.map(mapper) |> Enum.join(joiner)` => `lhs |> Enum.map_join(joiner, mapper)` | ||
- `lhs |> Enum.map(mapper) |> Enum.into(empty_map)` => `lhs |> Map.new(mapper)` | ||
- `lhs |> Enum.map(mapper) |> Enum.into(collectable)` => `lhs |> Enum.into(collectable, mapper)` | ||
- `lhs |> Enum.into(%{}, ...) => lhs |> Map.new(...)` | ||
- `lhs |> Enum.map(mapper) |> Map.new()` => `lhs |> Map.new(mapper)` mapset & keyword also | ||
- `lhs |> Map.merge(%{key: value}) => lhs |> Map.put(key, value)` (keyword literal also) | ||
|
||
## Unpiping Single Pipes | ||
|
||
- notably, optimizations might turn a 2 pipe into a single pipe | ||
- doesn't unpipe when we're starting w/ quote | ||
- pretty straight forward i daresay |
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,52 @@ | ||
# Single Node Styles | ||
|
||
## Elixir Deprecation Rewrites | ||
|
||
1.15+ | ||
|
||
- Logger.warn -> Logger.warning | ||
- Path.safe_relative_to/2 => Path.safe_relative/2 | ||
- Enum/String.slice/2 w/ ranges -> explicit steps | ||
- ~R/my_regex/ -> ~r/my_regex/ | ||
- Date.range/2 -> Date.range/3 when decreasing range | ||
- IO.read/bin_read -> use `:eof` instead of `:all` | ||
1.16+ | ||
- File.stream!(file, options, line_or_bytes) => File.stream!(file, line_or_bytes, options) | ||
|
||
## Literal Rewrites | ||
|
||
- string sigils | ||
- large base 10 numbers | ||
|
||
## Function Optimizations | ||
|
||
These apply to the piped versions as well | ||
|
||
- Enum.into(%{}/Map/Keyword/MapSet.new) -> X.new | ||
- Map/Keyword.merge w/ single key literal -> X.put | ||
- Enum.reverse(foo) ++ bar -> Enum.reverse(foo, bar) | ||
|
||
## Function Readability | ||
|
||
- Timex.now/0 -> DateTime.utc_now/0 | ||
- DateModule.compare(x, y) == :lt/:gt -> DateModule.before?/after? | ||
|
||
## Code Readability | ||
- put matches on right | ||
- `Credo.Check.Readability.PreferImplicitTry` | ||
|
||
## Consistency | ||
- `def foo()` -> `def foo` | ||
|
||
## Credo Rules This Hit | ||
|
||
* Credo.Check.Consistency.ParameterPatternMatching | ||
* Credo.Check.Readability.LargeNumbers | ||
* Credo.Check.Readability.ParenthesesOnZeroArityDefs | ||
* Credo.Check.Readability.PreferImplicitTry | ||
* Credo.Check.Readability.StringSigils | ||
* Credo.Check.Readability.WithSingleClause | ||
* Credo.Check.Refactor.CaseTrivialMatches | ||
* Credo.Check.Refactor.CondStatements | ||
* Credo.Check.Refactor.RedundantWithClauseResult | ||
* Credo.Check.Refactor.WithClauses |
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
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