Skip to content

Commit

Permalink
chore: update credo/check & fix credo issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Oct 11, 2023
1 parent 73754df commit 3015aaf
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 4 deletions.
23 changes: 23 additions & 0 deletions .check.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
## all available options with default values (see `mix check` docs for description)
# parallel: true,
# skipped: true,

## list of tools (see `mix check` docs for defaults)
tools: [
## curated tools may be disabled (e.g. the check for compilation warnings)
# {:compiler, false},

## ...or adjusted (e.g. use one-line formatter for more compact credo output)
# {:credo, "mix credo --format oneline"},

{:check_formatter, command: "mix spark.formatter --check"},
{:check_cheat_sheets, command: "mix spark.cheat_sheets --check"},
{:doctor, false}

## custom new tools may be added (mix tasks or arbitrary commands)
# {:my_mix_task, command: "mix release", env: %{"MIX_ENV" => "prod"}},
# {:my_arbitrary_tool, command: "npm test", cd: "assets"},
# {:my_arbitrary_script, command: ["my_script", "argument with spaces"], cd: "scripts"}
]
]
190 changes: 190 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# 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: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
# This check was erroring on sigils so I had to disable it
{Credo.Check.Consistency.SpaceAroundOperators, false},
{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, false},
# 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, 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, false},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{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, []},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, false},
{Credo.Check.Refactor.FunctionArity, false},
{Credo.Check.Refactor.LongQuoteBlocks, false},
{Credo.Check.Refactor.MapInto, false},
{Credo.Check.Refactor.MatchInCondition, false},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, [max_nesting: 10]},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},

#
## Warnings
#
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.LazyLogging, false},
{Credo.Check.Warning.MixEnv, false},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{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, []},

#
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)

#
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
#
# {Credo.Check.Readability.StrictModuleLayout,
# order: [:shortdoc, :moduledoc, :behaviour, :use, :defstruct, :type, :import, :alias, :require],
# ignore: [:module_attribute, :type]},
{Credo.Check.Readability.StrictModuleLayout, false},
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
{Credo.Check.Consistency.UnusedVariableNames, false},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.AliasAs, false},
{Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Readability.SinglePipe, false},
{Credo.Check.Readability.WithCustomTaggedTuple, false},
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.Apply, false},
{Credo.Check.Refactor.AppendSingleItem, false},
{Credo.Check.Refactor.DoubleBooleanNegation, false},
{Credo.Check.Refactor.ModuleDependencies, false},
{Credo.Check.Refactor.NegatedIsNil, false},
{Credo.Check.Refactor.PipeChainStart, false},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.LeakyEnvironment, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Warning.UnsafeToAtom, false}

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
]
}
1 change: 1 addition & 0 deletions lib/registry/registry.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPaperTrail.Registry do
@moduledoc "Deprecated in favor of `AshPaperTrail.Api`. Extends a registry to include the versions of paper trail resources. "
use Spark.Dsl.Extension,
transformers: [
AshPaperTrail.Registry.Transformers.AddResourceVersions
Expand Down
3 changes: 0 additions & 3 deletions lib/resource/transformers/relate_version_resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ defmodule AshPaperTrail.Resource.Transformers.RelateVersionResource do
relationship
| source: Transformer.get_persisted(dsl_state, :module)
})}
else
other ->
other
end
end

Expand Down
3 changes: 2 additions & 1 deletion test/ash_paper_trail_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
defmodule AshPaperTrailTest do
@moduledoc false
use ExUnit.Case

alias AshPaperTrail.Test.{Posts, Articles, Accounts}
alias AshPaperTrail.Test.{Accounts, Articles, Posts}

@valid_attrs %{
subject: "subject",
Expand Down
1 change: 1 addition & 0 deletions test/support/accounts/api.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPaperTrail.Test.Accounts.Api do
@moduledoc false
use Ash.Api, validate_config_inclusion?: false

resources do
Expand Down
1 change: 1 addition & 0 deletions test/support/accounts/news_feed.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPaperTrail.Test.Accounts.NewsFeed do
@moduledoc false
use Ash.Resource,
data_layer: Ash.DataLayer.Ets,
validate_api_inclusion?: false
Expand Down
1 change: 1 addition & 0 deletions test/support/accounts/user.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPaperTrail.Test.Accounts.User do
@moduledoc false
use Ash.Resource,
data_layer: Ash.DataLayer.Ets,
validate_api_inclusion?: false
Expand Down
1 change: 1 addition & 0 deletions test/support/articles/api.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPaperTrail.Test.Articles.Api do
@moduledoc false
use Ash.Api, validate_config_inclusion?: false

resources do
Expand Down
1 change: 1 addition & 0 deletions test/support/articles/article.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPaperTrail.Test.Articles.Article do
@moduledoc false
use Ash.Resource,
data_layer: Ash.DataLayer.Ets,
extensions: [AshPaperTrail.Resource],
Expand Down
1 change: 1 addition & 0 deletions test/support/articles/registry.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPaperTrail.Test.Articles.Registry do
@moduledoc false
use Ash.Registry,
extensions: [Ash.Registry.ResourceValidations, AshPaperTrail.Registry]

Expand Down
1 change: 1 addition & 0 deletions test/support/posts/api.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPaperTrail.Test.Posts.Api do
@moduledoc false
use Ash.Api, extensions: [AshPaperTrail.Api], validate_config_inclusion?: false

resources do
Expand Down
1 change: 1 addition & 0 deletions test/support/posts/author.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPaperTrail.Test.Posts.Author do
@moduledoc false
use Ash.Resource,
data_layer: :embedded,
validate_api_inclusion?: false
Expand Down
1 change: 1 addition & 0 deletions test/support/posts/post.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPaperTrail.Test.Posts.Post do
@moduledoc false
use Ash.Resource,
data_layer: Ash.DataLayer.Ets,
extensions: [AshPaperTrail.Resource],
Expand Down
1 change: 1 addition & 0 deletions test/support/posts/tag.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule AshPaperTrail.Test.Posts.Tag do
@moduledoc false
use Ash.Resource,
data_layer: :embedded,
validate_api_inclusion?: false
Expand Down
1 change: 1 addition & 0 deletions test/support/tenant.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
defmodule AshPaperTrail.Test.Tenant do
@moduledoc false
def parse_tenant(tenant), do: tenant
end

0 comments on commit 3015aaf

Please sign in to comment.