Skip to content

Commit

Permalink
Merge branch 'master' into rl/tasks-to-jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ruilopesm committed Nov 12, 2023
2 parents 7eb3359 + 1cd84e4 commit 8cfe57a
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 10 deletions.
169 changes: 169 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
%{
#
# 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, false},

#
## 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.FilterFilter, []},
{Credo.Check.Refactor.RejectReject, []},
{Credo.Check.Refactor.RedundantWithClauseResult, []},

#
## Warnings
#
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{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.SeparateAliasRequire, []},
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
{Credo.Check.Readability.SinglePipe, []},
{Credo.Check.Readability.Specs, []},
{Credo.Check.Readability.StrictModuleLayout, []},
{Credo.Check.Readability.WithCustomTaggedTuple, []},
{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.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 @@ -95,7 +95,7 @@ defmodule Safira.MixProject do
"ecto.setup": ["ecto.create", "ecto.migrate", "ecto.seed"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate", "test"],
lint: ["credo --strict --all"]
lint: ["credo -C default"]
]
end
end
9 changes: 5 additions & 4 deletions priv/repo/seeds/accounts.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Safira.Repo.Seeds.Accounts do
@moduledoc false

alias Mix.Tasks.Gen.{AttendeesWithPassword, Companies, Staffs}
alias Safira.Accounts
alias Safira.Accounts.User
alias Safira.Repo
Expand All @@ -13,20 +14,20 @@ defmodule Safira.Repo.Seeds.Accounts do
end

defp seed_companies do
Mix.Tasks.Gen.Companies.run(["data/sponsors.csv"])
Companies.run(["data/sponsors.csv"])
end

defp seed_staffs do
Mix.Tasks.Gen.Staffs.run(["10"])
Staffs.run(["10"])
end

defp seed_attendees do
Mix.Tasks.Gen.AttendeesWithPassword.run(["100"])
AttendeesWithPassword.run(["100"])
end

# All tasks generate random passwords, which is not very useful in a development
# environment. So this function changes the passwords of all users to "password1234"
defp reset_passwords() do
defp reset_passwords do
Accounts.list_users()
|> Enum.each(fn u -> Repo.update(User.update_password_changeset(u, %{password: "password1234"})) end)
end
Expand Down
3 changes: 2 additions & 1 deletion priv/repo/seeds/contest.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Safira.Repo.Seeds.Contest do
@moduledoc false

alias Mix.Tasks.Gen.Badges
alias Safira.Accounts.Attendee
alias Safira.Contest
alias Safira.Contest.Badge
Expand All @@ -14,7 +15,7 @@ defmodule Safira.Repo.Seeds.Contest do
end

defp seed_badges do
Mix.Tasks.Gen.Badges.run(["data/badges.csv"])
Badges.run(["data/badges.csv"])
end

defp seed_redeems do
Expand Down
6 changes: 4 additions & 2 deletions priv/repo/seeds/roulette.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Safira.Repo.Seeds.Roulette do
@moduledoc false

alias Mix.Tasks.Gen.Prizes
alias Safira.Accounts.Attendee
alias Safira.Repo
alias Safira.Roulette
Expand All @@ -13,7 +14,7 @@ defmodule Safira.Repo.Seeds.Roulette do
end

defp seed_prizes do
Mix.Tasks.Gen.Prizes.run(["data/wheel.csv"])
Prizes.run(["data/wheel.csv"])
end

defp seed_spins do
Expand All @@ -23,7 +24,8 @@ defmodule Safira.Repo.Seeds.Roulette do

# Making sure attendee has enough tokens to spin the wheel
at = at
|> Attendee.update_token_balance_changeset(%{token_balance: at.token_balance + Application.fetch_env!(:safira, :roulette_cost)})
|> Attendee.update_token_balance_changeset(
%{token_balance: at.token_balance + Application.fetch_env!(:safira, :roulette_cost)})
|> Repo.update!()

Roulette.spin_transaction(at)
Expand Down
5 changes: 3 additions & 2 deletions priv/repo/seeds/store.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
defmodule Safira.Repo.Seeds.Store do
@moduledoc false

alias Mix.Tasks.Gen.Redeemables
alias Safira.Accounts.Attendee
alias Safira.Repo
alias Safira.Store
alias Safira.Store.Redeemable
alias Safira.Repo

@buys_amount 30

Expand All @@ -14,7 +15,7 @@ defmodule Safira.Repo.Seeds.Store do
end

defp seed_redeemables do
Mix.Tasks.Gen.Redeemables.run(["data/redeemables.csv"])
Redeemables.run(["data/redeemables.csv"])
end

defp seed_buys do
Expand Down

0 comments on commit 8cfe57a

Please sign in to comment.