From 640c0cb0b869ae0ab38fe2ae14003ab1ec5d82d7 Mon Sep 17 00:00:00 2001 From: Rui Lopes <76881129+RuiL1904@users.noreply.github.com> Date: Sat, 19 Aug 2023 13:24:08 +0100 Subject: [PATCH] chore: add credo configuration --- .credo.exs | 175 ++++++++++++++++++++++++++++++ mix.exs | 2 +- priv/repo/seeds/accounts.exs | 2 +- priv/repo/seeds/activities.exs | 17 +-- priv/repo/seeds/courses.exs | 10 +- priv/repo/seeds/departments.exs | 6 +- priv/repo/seeds/memberships.exs | 8 +- priv/repo/seeds/news.exs | 2 +- priv/repo/seeds/organizations.exs | 5 +- priv/repo/seeds/partners.exs | 5 +- 10 files changed, 199 insertions(+), 33 deletions(-) create mode 100644 .credo.exs diff --git a/.credo.exs b/.credo.exs new file mode 100644 index 000000000..1ded805e4 --- /dev/null +++ b/.credo.exs @@ -0,0 +1,175 @@ +%{ + # + # You can have as many configs as you like in the `configs:` field. + configs: [ + %{ + # + # Run any config using `mix credo -C `. If no config name is given + # "default" is used. + # + name: "default", + files: %{ + included: [ + "lib/", + "test/", + "priv/repo/" + ], + excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"] + }, + plugins: [], + requires: [], + strict: true, + parse_timeout: 5000, + color: true, + # + # You can customize the parameters of any check by adding a second element + # to the tuple. + # + # To disable a check put `false` as second element: + # + # {Credo.Check.Design.DuplicatedCode, false} + # + checks: %{ + enabled: [ + # + ## Consistency Checks + # + {Credo.Check.Consistency.ExceptionNames, []}, + {Credo.Check.Consistency.LineEndings, []}, + {Credo.Check.Consistency.ParameterPatternMatching, []}, + {Credo.Check.Consistency.SpaceAroundOperators, []}, + {Credo.Check.Consistency.SpaceInParentheses, []}, + {Credo.Check.Consistency.TabsOrSpaces, []}, + + # + ## Design Checks + # + # You can customize the priority of any check + # Priority values are: `low, normal, high, higher` + # + {Credo.Check.Design.AliasUsage, + [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]}, + {Credo.Check.Design.TagTODO, false}, + {Credo.Check.Design.TagFIXME, []}, + + # + ## Readability Checks + # + {Credo.Check.Readability.AliasOrder, []}, + {Credo.Check.Readability.FunctionNames, []}, + {Credo.Check.Readability.LargeNumbers, []}, + {Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]}, + {Credo.Check.Readability.ModuleAttributeNames, []}, + {Credo.Check.Readability.ModuleDoc, []}, + {Credo.Check.Readability.ModuleNames, []}, + {Credo.Check.Readability.ParenthesesInCondition, []}, + {Credo.Check.Readability.ParenthesesOnZeroArityDefs, []}, + {Credo.Check.Readability.PipeIntoAnonymousFunctions, []}, + {Credo.Check.Readability.PredicateFunctionNames, []}, + {Credo.Check.Readability.PreferImplicitTry, []}, + {Credo.Check.Readability.RedundantBlankLines, []}, + {Credo.Check.Readability.Semicolons, []}, + {Credo.Check.Readability.SpaceAfterCommas, []}, + {Credo.Check.Readability.StringSigils, []}, + {Credo.Check.Readability.TrailingBlankLine, []}, + {Credo.Check.Readability.TrailingWhiteSpace, []}, + {Credo.Check.Readability.UnnecessaryAliasExpansion, []}, + {Credo.Check.Readability.VariableNames, []}, + {Credo.Check.Readability.WithSingleClause, []}, + + # + ## Refactoring Opportunities + # + {Credo.Check.Refactor.Apply, []}, + {Credo.Check.Refactor.CondStatements, []}, + {Credo.Check.Refactor.CyclomaticComplexity, []}, + {Credo.Check.Refactor.FunctionArity, []}, + {Credo.Check.Refactor.LongQuoteBlocks, []}, + {Credo.Check.Refactor.MatchInCondition, []}, + {Credo.Check.Refactor.MapJoin, []}, + {Credo.Check.Refactor.NegatedConditionsInUnless, []}, + {Credo.Check.Refactor.NegatedConditionsWithElse, []}, + {Credo.Check.Refactor.Nesting, []}, + {Credo.Check.Refactor.UnlessWithElse, []}, + {Credo.Check.Refactor.WithClauses, []}, + {Credo.Check.Refactor.FilterCount, []}, + {Credo.Check.Refactor.FilterFilter, []}, + {Credo.Check.Refactor.RejectReject, []}, + {Credo.Check.Refactor.RedundantWithClauseResult, []}, + + # + ## Warnings + # + {Credo.Check.Warning.ApplicationConfigInModuleAttribute, []}, + {Credo.Check.Warning.BoolOperationOnSameValues, []}, + {Credo.Check.Warning.Dbg, []}, + {Credo.Check.Warning.ExpensiveEmptyEnumCheck, []}, + {Credo.Check.Warning.IExPry, []}, + {Credo.Check.Warning.IoInspect, []}, + {Credo.Check.Warning.MissedMetadataKeyInLoggerConfig, []}, + {Credo.Check.Warning.OperationOnSameValues, []}, + {Credo.Check.Warning.OperationWithConstantResult, []}, + {Credo.Check.Warning.RaiseInsideRescue, []}, + {Credo.Check.Warning.SpecWithStruct, []}, + {Credo.Check.Warning.WrongTestFileExtension, []}, + {Credo.Check.Warning.UnusedEnumOperation, []}, + {Credo.Check.Warning.UnusedFileOperation, []}, + {Credo.Check.Warning.UnusedKeywordOperation, []}, + {Credo.Check.Warning.UnusedListOperation, []}, + {Credo.Check.Warning.UnusedPathOperation, []}, + {Credo.Check.Warning.UnusedRegexOperation, []}, + {Credo.Check.Warning.UnusedStringOperation, []}, + {Credo.Check.Warning.UnusedTupleOperation, []}, + {Credo.Check.Warning.UnsafeExec, []} + ], + disabled: [ + # + # Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`) + + # + # Controversial and experimental checks (opt-in, just move the check to `:enabled` + # and be sure to use `mix credo --strict` to see low priority checks) + # + {Credo.Check.Consistency.MultiAliasImportRequireUse, []}, + {Credo.Check.Consistency.UnusedVariableNames, []}, + {Credo.Check.Design.DuplicatedCode, []}, + {Credo.Check.Design.SkipTestWithoutComment, []}, + {Credo.Check.Readability.AliasAs, []}, + {Credo.Check.Readability.BlockPipe, []}, + {Credo.Check.Readability.ImplTrue, []}, + {Credo.Check.Readability.MultiAlias, []}, + {Credo.Check.Readability.NestedFunctionCalls, []}, + {Credo.Check.Readability.OneArityFunctionInPipe, []}, + {Credo.Check.Readability.SeparateAliasRequire, []}, + {Credo.Check.Readability.SingleFunctionToBlockPipe, []}, + {Credo.Check.Readability.SinglePipe, []}, + {Credo.Check.Readability.Specs, []}, + {Credo.Check.Readability.StrictModuleLayout, []}, + {Credo.Check.Readability.WithCustomTaggedTuple, []}, + {Credo.Check.Readability.OnePipePerLine, []}, + {Credo.Check.Refactor.ABCSize, []}, + {Credo.Check.Refactor.AppendSingleItem, []}, + {Credo.Check.Refactor.DoubleBooleanNegation, []}, + {Credo.Check.Refactor.FilterReject, []}, + {Credo.Check.Refactor.IoPuts, []}, + {Credo.Check.Refactor.MapMap, []}, + {Credo.Check.Refactor.ModuleDependencies, []}, + {Credo.Check.Refactor.NegatedIsNil, []}, + {Credo.Check.Refactor.PassAsyncInTestCases, []}, + {Credo.Check.Refactor.PipeChainStart, []}, + {Credo.Check.Refactor.RejectFilter, []}, + {Credo.Check.Refactor.VariableRebinding, []}, + {Credo.Check.Warning.LazyLogging, []}, + {Credo.Check.Warning.LeakyEnvironment, []}, + {Credo.Check.Warning.MapGetUnsafePass, []}, + {Credo.Check.Warning.MixEnv, []}, + {Credo.Check.Warning.UnsafeToAtom, []} + + # + # Custom checks can be created using `mix credo.gen.check`. + # + ] + } + } + ] +} diff --git a/mix.exs b/mix.exs index 1f0fb0d4b..50e877fe2 100644 --- a/mix.exs +++ b/mix.exs @@ -103,7 +103,7 @@ defmodule Atomic.MixProject do "ecto.reset": ["ecto.drop", "ecto.setup"], test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"], "assets.deploy": ["tailwind default --minify", "esbuild default --minify", "phx.digest"], - lint: ["credo --strict --all"], + lint: ["credo -C default"], check: [ "clean", "deps.unlock --check-unused", diff --git a/priv/repo/seeds/accounts.exs b/priv/repo/seeds/accounts.exs index dd6c763db..3552d9478 100644 --- a/priv/repo/seeds/accounts.exs +++ b/priv/repo/seeds/accounts.exs @@ -1,8 +1,8 @@ defmodule Atomic.Repo.Seeds.Accounts do alias Atomic.Accounts alias Atomic.Accounts.{Course, User} - alias Atomic.Repo alias Atomic.Organizations.Organization + alias Atomic.Repo def run do case Repo.all(User) do diff --git a/priv/repo/seeds/activities.exs b/priv/repo/seeds/activities.exs index 8d4efec4a..a21acfcb2 100644 --- a/priv/repo/seeds/activities.exs +++ b/priv/repo/seeds/activities.exs @@ -1,13 +1,8 @@ defmodule Atomic.Repo.Seeds.Activities do - alias Atomic.Activities.SessionDepartment - alias Atomic.Repo - alias Atomic.Accounts.User + alias Atomic.Activities.{Activity, ActivitySession, Enrollment, Session, SessionDepartment} alias Atomic.Organizations.Department - alias Atomic.Activities - alias Atomic.Activities.SessionDepartment - alias Atomic.Activities.Session - alias Atomic.Activities.{Activity, Enrollment} + alias Atomic.Repo def run do seed_activities() @@ -15,7 +10,7 @@ defmodule Atomic.Repo.Seeds.Activities do seed_session_departments() end - def seed_activities() do + def seed_activities do case Repo.all(Activity) do [] -> location = %{ @@ -189,7 +184,7 @@ defmodule Atomic.Repo.Seeds.Activities do end end - def seed_activities_departments() do + def seed_activities_departments do case Repo.all(SessionDepartment) do [] -> department = Repo.get_by(Department, name: "Merchandise and Partnerships") @@ -209,7 +204,7 @@ defmodule Atomic.Repo.Seeds.Activities do end end - def seed_enrollments() do + def seed_enrollments do case Repo.all(Enrollment) do [] -> users = Repo.all(User) @@ -229,7 +224,7 @@ defmodule Atomic.Repo.Seeds.Activities do end end - def seed_session_departments() do + def seed_session_departments do case Repo.all(SessionDepartment) do [] -> department = Repo.get_by(Department, name: "CAOS") diff --git a/priv/repo/seeds/courses.exs b/priv/repo/seeds/courses.exs index 85fd21809..bf690b71a 100644 --- a/priv/repo/seeds/courses.exs +++ b/priv/repo/seeds/courses.exs @@ -1,6 +1,10 @@ defmodule Atomic.Repo.Seeds.Courses do + alias Atomic.Accounts + alias Atomic.Accounts.Course + alias Atomic.Repo + def run do - case Atomic.Repo.all(Atomic.Accounts.Course) do + case Repo.all(Course) do [] -> create_courses() @@ -9,11 +13,11 @@ defmodule Atomic.Repo.Seeds.Courses do end end - def create_courses() do + def create_courses do File.read!("data/courses.txt") |> String.split("\n") |> Enum.filter(fn name -> name != "" end) - |> Enum.map(fn name -> Atomic.Accounts.create_course(%{name: name}) end) + |> Enum.map(fn name -> Accounts.create_course(%{name: name}) end) end end diff --git a/priv/repo/seeds/departments.exs b/priv/repo/seeds/departments.exs index 55bdf9ffa..5489d733f 100644 --- a/priv/repo/seeds/departments.exs +++ b/priv/repo/seeds/departments.exs @@ -1,14 +1,12 @@ defmodule Atomic.Repo.Seeds.Departments do + alias Atomic.Organizations.{Department, Organization} alias Atomic.Repo - alias Atomic.Organizations.Department - alias Atomic.Organizations.Organization - def run do seed_departments() end - def seed_departments() do + def seed_departments do case Repo.all(Department) do [] -> Department.changeset( diff --git a/priv/repo/seeds/memberships.exs b/priv/repo/seeds/memberships.exs index f5322649f..baf2c84dc 100644 --- a/priv/repo/seeds/memberships.exs +++ b/priv/repo/seeds/memberships.exs @@ -1,10 +1,6 @@ defmodule Atomic.Repo.Seeds.Memberships do - alias Atomic.Organizations.Organization - alias Atomic.Organizations.Membership alias Atomic.Accounts.User - alias Atomic.Organizations.Board - alias Atomic.Organizations.BoardDepartments - alias Atomic.Organizations.UserOrganization + alias Atomic.Organizations.{Board, BoardDepartments, Membership, Organization, UserOrganization} alias Atomic.Repo def run do @@ -14,7 +10,7 @@ defmodule Atomic.Repo.Seeds.Memberships do seed_user_organizations() end - def seed_memberships() do + def seed_memberships do case Repo.all(Membership) do [] -> users = Repo.all(User) diff --git a/priv/repo/seeds/news.exs b/priv/repo/seeds/news.exs index fb7aea64d..a2f5150ae 100644 --- a/priv/repo/seeds/news.exs +++ b/priv/repo/seeds/news.exs @@ -7,7 +7,7 @@ defmodule Atomic.Repo.Seeds.News do seed_news() end - def seed_news() do + def seed_news do case Repo.all(New) do [] -> organizations = Repo.all(Organization) diff --git a/priv/repo/seeds/organizations.exs b/priv/repo/seeds/organizations.exs index da50b6bb9..231065c18 100644 --- a/priv/repo/seeds/organizations.exs +++ b/priv/repo/seeds/organizations.exs @@ -1,13 +1,12 @@ defmodule Atomic.Repo.Seeds.Organizations do - alias Atomic.Repo - alias Atomic.Organizations.Organization + alias Atomic.Repo def run do seed_organizations() end - def seed_organizations() do + def seed_organizations do case Repo.all(Organization) do [] -> Organization.changeset( diff --git a/priv/repo/seeds/partners.exs b/priv/repo/seeds/partners.exs index 44348b869..e911cf796 100644 --- a/priv/repo/seeds/partners.exs +++ b/priv/repo/seeds/partners.exs @@ -1,13 +1,12 @@ defmodule Atomic.Repo.Seeds.Partners do - alias Atomic.Organizations.Partner - alias Atomic.Organizations.Organization + alias Atomic.Organizations.{Organization, Partner} alias Atomic.Repo def run do seed_partners() end - def seed_partners() do + def seed_partners do case Repo.all(Partner) do [] -> organizations = Repo.all(Organization)