Skip to content

Commit

Permalink
chore: add credo configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ruilopesm committed Aug 19, 2023
1 parent cdc6dd5 commit 640c0cb
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 33 deletions.
175 changes: 175 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -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 <name>`. 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`.
#
]
}
}
]
}
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion priv/repo/seeds/accounts.exs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 6 additions & 11 deletions priv/repo/seeds/activities.exs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
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()
seed_enrollments()
seed_session_departments()
end

def seed_activities() do
def seed_activities do
case Repo.all(Activity) do
[] ->
location = %{
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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")
Expand Down
10 changes: 7 additions & 3 deletions priv/repo/seeds/courses.exs
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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

Expand Down
6 changes: 2 additions & 4 deletions priv/repo/seeds/departments.exs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
8 changes: 2 additions & 6 deletions priv/repo/seeds/memberships.exs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion priv/repo/seeds/news.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions priv/repo/seeds/organizations.exs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
5 changes: 2 additions & 3 deletions priv/repo/seeds/partners.exs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 640c0cb

Please sign in to comment.