Skip to content

Commit

Permalink
chore: add credo to ci pipeline #315
Browse files Browse the repository at this point in the history
  • Loading branch information
nwittstruck committed Jun 15, 2024
1 parent ce75bf3 commit eff213c
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 18 deletions.
219 changes: 219 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https://github.com/rrrene/credo/issues
#
%{
#
# 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",
#
# These are the files included in the analysis:
files: %{
#
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: [
"lib/",
"src/",
"test/",
"web/",
"apps/*/lib/",
"apps/*/src/",
"apps/*/test/",
"apps/*/web/"
],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
#
# Load and configure plugins here:
#
plugins: [],
#
# If you create your own checks, you must specify the source files for
# them here, so they can be loaded by Credo before running the analysis.
#
requires: [],
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: false,
#
# To modify the timeout for parsing files, change this value:
#
parse_timeout: 5000,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
#
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.TagFIXME, []},
# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
#
{Credo.Check.Design.TagTODO, [exit_status: 2]},

#
## 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.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.FilterCount, []},
{Credo.Check.Refactor.FilterFilter, []},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
{Credo.Check.Refactor.MapJoin, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.RedundantWithClauseResult, []},
{Credo.Check.Refactor.RejectReject, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},

#
## 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.UnsafeExec, []},
{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.WrongTestFileExtension, []}
],
disabled: [
# Checks that need work to be included:
{Credo.Check.Readability.ModuleDoc, []},

#
# Checks scheduled for next check update (opt-in for now)
{Credo.Check.Refactor.UtcNowTruncate, []},

#
# 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.OnePipePerLine, []},
{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.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, []}

# {Credo.Check.Refactor.MapInto, []},

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
}
]
}
28 changes: 23 additions & 5 deletions .github/workflows/on_push_branch__execute_ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
# This would also remove the need to install cmake manually in each step:
container: hexpm/elixir:1.15.8-erlang-26.2.5-debian-bullseye-20240513-slim


steps:
# See https://github.com/actions/checkout
- uses: actions/checkout@v4
Expand Down Expand Up @@ -109,7 +108,6 @@ jobs:
restore-keys: ${{ runner.os }}-mix-v4

- run: mix do local.hex --force, local.rebar --force

- run: mix format --check-formatted

check_mix_gettext_extract_up_to_date:
Expand All @@ -131,7 +129,6 @@ jobs:
restore-keys: ${{ runner.os }}-mix-v4

- run: mix do local.hex --force, local.rebar --force
- run: mix compile
- run: mix gettext.extract --check-up-to-date

check_mix_sobelow:
Expand All @@ -153,5 +150,26 @@ jobs:
restore-keys: ${{ runner.os }}-mix-v4

- run: mix do local.hex --force, local.rebar --force
- run: mix compile
- run: mix sobelow --config
- run: mix sobelow --config


check_mix_credo:
runs-on: ubuntu-latest
container: hexpm/elixir:1.15.8-erlang-26.2.5-debian-bullseye-20240513-slim

needs: build_deps

steps:
- name: Check out repository code
uses: actions/checkout@v4

- uses: actions/cache@v4
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-v4-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-v4

- run: mix do local.hex --force, local.rebar --force
- run: mix credo
1 change: 1 addition & 0 deletions lib/mindwendel/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ defmodule Mindwendel.Accounts do
"""
def merge_brainstorming_user(%Brainstorming{} = brainstorming, %User{} = user) do
# credo:disable-for-next-line
unless user.id in Enum.map(brainstorming.users, fn e -> e.id end) do
brainstorming_users = [user | brainstorming.users]

Expand Down
1 change: 1 addition & 0 deletions lib/mindwendel/brainstormings/brainstorming.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule Mindwendel.Brainstormings.Brainstorming do
schema "brainstormings" do
field :name, :string
field :option_show_link_to_settings, :boolean
# credo:disable-for-next-line
# Todo: The following line can be changed `field :admin_url_id, Ecto.UUID, autogenerate: true`
# This will automatically generate a UUID for the admin_url_id which would make the method `gen_admin_url_id/2` obsolete.
field :admin_url_id, :binary_id
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ defmodule Mindwendel.MixProject do
{:plug_cowboy, "2.7.1"},
{:cowboy, "2.12.0"},
{:postgrex, "0.18.0"},
{:sobelow, "0.13.0", only: :dev},
{:sobelow, "0.13.0", only: [:dev, :test], runtime: false},
{:credo, "1.7.7", only: [:dev, :test], runtime: false},
{:telemetry_metrics, "1.0.0"},
{:telemetry_poller, "1.1.0"},
{:timex, "3.7.11"},
Expand Down
2 changes: 2 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
%{
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"bypass": {:hex, :bypass, "2.1.0", "909782781bf8e20ee86a9cabde36b259d44af8b9f38756173e8f5e2e1fabb9b1", [:mix], [{:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "d9b5df8fa5b7a6efa08384e9bbecfe4ce61c77d28a4282f79e02f1ef78d96b80"},
"castore": {:hex, :castore, "1.0.7", "b651241514e5f6956028147fe6637f7ac13802537e895a724f90bf3e36ddd1dd", [:mix], [], "hexpm", "da7785a4b0d2a021cd1292a60875a784b6caef71e76bf4917bdee1f390455cf5"},
"certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"},
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"},
"cowboy": {:hex, :cowboy, "2.12.0", "f276d521a1ff88b2b9b4c54d0e753da6c66dd7be6c9fca3d9418b561828a3731", [:make, :rebar3], [{:cowlib, "2.13.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "8a7abe6d183372ceb21caa2709bec928ab2b72e18a3911aa1771639bef82651e"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
"cowlib": {:hex, :cowlib, "2.13.0", "db8f7505d8332d98ef50a3ef34b34c1afddec7506e4ee4dd4a3a266285d282ca", [:make, :rebar3], [], "hexpm", "e1e1284dc3fc030a64b1ad0d8382ae7e99da46c3246b815318a4b848873800a4"},
"credo": {:hex, :credo, "1.7.7", "771445037228f763f9b2afd612b6aa2fd8e28432a95dbbc60d8e03ce71ba4446", [: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", "8bc87496c9aaacdc3f90f01b7b0582467b69b4bd2441fe8aae3109d843cc2f2e"},
"csv": {:hex, :csv, "3.2.1", "6d401f1ed33acb2627682a9ab6021e96d33ca6c1c6bccc243d8f7e2197d032f5", [:mix], [], "hexpm", "8f55a0524923ae49e97ff2642122a2ce7c61e159e7fe1184670b2ce847aee6c8"},
"dart_sass": {:hex, :dart_sass, "0.7.0", "7979e056cb74fd6843e1c72db763cffc7726a9192a657735b7d24c0d9c26a1ce", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "4a8e70bca41aa00846398abdf5ad8a64d7907a0f7bf40145cd2e40d5971629f2"},
"db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"},
Expand Down
6 changes: 3 additions & 3 deletions test/mindwendel/brainstormings_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ defmodule Mindwendel.BrainstormingsTest do
# reload brainstorming:
brainstorming = Brainstormings.get_brainstorming!(brainstorming.id)
brainstorming = brainstorming |> Repo.preload([:ideas])
assert Enum.count(brainstorming.ideas) == 0
assert Enum.empty?(brainstorming.ideas)
end

test "empty/1 also clears likes and labels from ideas", %{brainstorming: brainstorming} do
Expand All @@ -192,7 +192,7 @@ defmodule Mindwendel.BrainstormingsTest do
# reload brainstorming:
brainstorming = Brainstormings.get_brainstorming!(brainstorming.id)

assert Enum.count(brainstorming.ideas) == 0
assert Enum.empty?(brainstorming.ideas)
assert Repo.get_by(Idea, id: idea.id) == nil
assert Repo.get_by(IdeaIdeaLabel, idea_id: idea.id) == nil
assert Repo.get_by(Like, id: like.id) == nil
Expand All @@ -215,7 +215,7 @@ defmodule Mindwendel.BrainstormingsTest do
brainstorming = Brainstormings.get_brainstorming!(brainstorming.id)
brainstorming = brainstorming |> Repo.preload([:ideas])
other_brainstorming = other_brainstorming |> Repo.preload([:ideas])
assert Enum.count(brainstorming.ideas) == 0
assert Enum.empty?(brainstorming.ideas)
assert Enum.count(other_brainstorming.ideas) == 1
end
end
Expand Down
13 changes: 7 additions & 6 deletions test/mindwendel/idea_labels_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ defmodule Mindwendel.IdeaLabelsTest do
assert Repo.one(IdeaIdeaLabel).idea_label_id == idea_label.id
assert Repo.all(IdeaLabel) |> Enum.count() == 5

assert Repo.all(
from idea_label in IdeaLabel,
where: is_nil(idea_label.brainstorming_id)
assert Enum.empty?(
Repo.all(
from idea_label in IdeaLabel,
where: is_nil(idea_label.brainstorming_id)
)
)
|> Enum.count() == 0
end
end

Expand All @@ -115,7 +116,7 @@ defmodule Mindwendel.IdeaLabelsTest do

test "removes successfully IdeaLabel from Idea", %{idea_label: idea_label, idea: idea} do
IdeaLabels.remove_idea_label_from_idea(idea, idea_label)
assert Repo.all(IdeaIdeaLabel) |> Enum.count() == 0
assert Enum.empty?(Repo.all(IdeaIdeaLabel))
end

test "does not break when removing IdeaLabel that is not connected to Idea yet", %{
Expand All @@ -126,7 +127,7 @@ defmodule Mindwendel.IdeaLabelsTest do
IdeaLabels.remove_idea_label_from_idea(idea, idea_label)
IdeaLabels.remove_idea_label_from_idea(idea, idea_label)

assert Repo.all(IdeaIdeaLabel) |> Enum.count() == 0
assert Enum.empty?(Repo.all(IdeaIdeaLabel))
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ defmodule MindwendelWeb.Admin.BrainstormingLive.EditTest do

# reload brainstorming to check for changes:
brainstorming = Brainstormings.get_brainstorming!(brainstorming.id)
assert Enum.count(brainstorming.ideas) == 0
assert Enum.empty?(brainstorming.ideas)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/repo/data_migrations/migrate_idea_labels_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Mindwendel.Repo.DataMigrations.MigrateIdealLabelsTest do
brainstorming: existing_brainstorming
} do
existing_brainstorming = Repo.preload(existing_brainstorming, :labels)
assert Enum.count(existing_brainstorming.labels) == 0
assert Enum.empty?(existing_brainstorming.labels)

MigrateIdealLabels.run()

Expand Down
Loading

0 comments on commit eff213c

Please sign in to comment.