From 594819af1f027d09dbf607a42c63a5b43cef4cfe Mon Sep 17 00:00:00 2001 From: Daniel Kukula Date: Fri, 29 Mar 2024 18:48:41 +0000 Subject: [PATCH] Add credo and styler --- .credo.exs | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ .formatter.exs | 1 + mix.exs | 4 ++- mix.lock | 4 +++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 .credo.exs diff --git a/.credo.exs b/.credo.exs new file mode 100644 index 0000000..d7578b9 --- /dev/null +++ b/.credo.exs @@ -0,0 +1,67 @@ +%{ + configs: [ + %{ + name: "default", + files: %{ + included: ["lib/", "src/", "web/", "apps/"], + excluded: [] + }, + plugins: [], + requires: [], + strict: false, + parse_timeout: 5000, + color: true, + checks: %{ + disabled: [ + # 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} + ] + } + } + ] +} diff --git a/.formatter.exs b/.formatter.exs index 5d1911d..ff7b6b3 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,5 +1,6 @@ # Used by "mix format" [ + plugins: [Styler], inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] |> Enum.flat_map(&Path.wildcard(&1, match_dot: true)) diff --git a/mix.exs b/mix.exs index b5399c3..578d292 100644 --- a/mix.exs +++ b/mix.exs @@ -50,7 +50,9 @@ defmodule ExtFit.MixProject do {:excoveralls, "~> 0.18.0", only: [:dev, :test], runtime: false}, {:ex_doc, "~> 0.31", only: :dev, runtime: false}, {:dialyxir, "~> 1.3", only: [:dev], runtime: false}, - {:csv, "~> 3.2", only: [:test]} + {:csv, "~> 3.2", only: [:test]}, + {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, + {:styler, "~> 0.11", only: [:dev, :test], runtime: false} ] end diff --git a/mix.lock b/mix.lock index 6b75acd..b736dd0 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,7 @@ %{ + "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, "cldr_utils": {:hex, :cldr_utils, "2.24.2", "364fa30be55d328e704629568d431eb74cd2f085752b27f8025520b566352859", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "3362b838836a9f0fa309de09a7127e36e67310e797d556db92f71b548832c7cf"}, + "credo": {:hex, :credo, "1.7.5", "643213503b1c766ec0496d828c90c424471ea54da77c8a168c725686377b9545", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f799e9b5cd1891577d8c773d245668aa74a2fcd15eb277f51a0131690ebfb3fd"}, "csv": {:hex, :csv, "3.2.1", "6d401f1ed33acb2627682a9ab6021e96d33ca6c1c6bccc243d8f7e2197d032f5", [:mix], [], "hexpm", "8f55a0524923ae49e97ff2642122a2ce7c61e159e7fe1184670b2ce847aee6c8"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"}, @@ -7,9 +9,11 @@ "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.31.1", "8a2355ac42b1cc7b2379da9e40243f2670143721dd50748bf6c3b1184dae2089", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3178c3a407c557d8343479e1ff117a96fd31bafe52a039079593fb0524ef61b0"}, "excoveralls": {:hex, :excoveralls, "0.18.0", "b92497e69465dc51bc37a6422226ee690ab437e4c06877e836f1c18daeb35da9", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1109bb911f3cb583401760be49c02cbbd16aed66ea9509fc5479335d284da60b"}, + "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"}, "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.4", "29563475afa9b8a2add1b7a9c8fb68d06ca7737648f28398e04461f008b69521", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f4ed47ecda66de70dd817698a703f8816daa91272e7e45812469498614ae8b29"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, + "styler": {:hex, :styler, "0.11.9", "2595393b94e660cd6e8b582876337cc50ff047d184ccbed42fdad2bfd5d78af5", [:mix], [], "hexpm", "8b7806ba1fdc94d0a75127c56875f91db89b75117fcc67572661010c13e1f259"}, }