Skip to content

chore: add credo fixes #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 216 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# 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 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.ModuleDoc, []},
{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`.
#
]
}
}
]
}
1 change: 0 additions & 1 deletion lib/blanks.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Blanks do
@moduledoc false
def replace(ast, replacements) do
replacements = List.wrap(replacements)

Expand Down
1 change: 0 additions & 1 deletion lib/display.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Display do
@moduledoc false
use GenServer

alias IO.ANSI
Expand Down
3 changes: 0 additions & 3 deletions lib/display/colours.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Display.Paint do
@moduledoc false
def red(str), do: painter().red(str)
def cyan(str), do: painter().cyan(str)
def green(str), do: painter().green(str)
Expand All @@ -14,7 +13,6 @@ defmodule Display.Paint do
end

defmodule Display.Colours do
@moduledoc false
alias IO.ANSI

def red(str), do: colourize(ANSI.red(), str)
Expand All @@ -28,7 +26,6 @@ defmodule Display.Colours do
end

defmodule Display.Uncoloured do
@moduledoc false
def red(str), do: str
def cyan(str), do: str
def green(str), do: str
Expand Down
1 change: 0 additions & 1 deletion lib/display/failure.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Display.Failure do
@moduledoc false
alias Display.Paint

@no_value :ex_unit_no_meaningful_value
Expand Down
1 change: 0 additions & 1 deletion lib/display/intro.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Display.Intro do
@moduledoc false
alias Display.Paint

def intro(module, modules) do
Expand Down
1 change: 0 additions & 1 deletion lib/display/notification.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Display.Notifications do
@moduledoc false
alias Display.Paint

def congratulate do
Expand Down
1 change: 0 additions & 1 deletion lib/display/progress_bar.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Display.ProgressBar do
@moduledoc false
@progress_bar_length 30

def progress_bar(%{current: current, total: total}) do
Expand Down
1 change: 0 additions & 1 deletion lib/elixir_koans.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule ElixirKoans do
@moduledoc false
use Application

def start(_type, _args) do
Expand Down
1 change: 0 additions & 1 deletion lib/execute.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Execute do
@moduledoc false
def run_module(module, callback \\ fn _result, _module, _koan -> nil end) do
Enum.reduce_while(module.all_koans, :passed, fn koan, _ ->
module
Expand Down
1 change: 0 additions & 1 deletion lib/koans.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Koans do
@moduledoc false
defp valid_name(name) do
Regex.match?(~r/([A-Z]|\.\.\.).+/, name)
end
Expand Down
1 change: 0 additions & 1 deletion lib/koans/01_equalities.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Equalities do
@moduledoc false
use Koans

@intro """
Expand Down
1 change: 0 additions & 1 deletion lib/koans/02_strings.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Strings do
@moduledoc false
use Koans

@intro "Strings"
Expand Down
9 changes: 4 additions & 5 deletions lib/koans/03_numbers.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Numbers do
@moduledoc false
require Integer
use Koans

Expand Down Expand Up @@ -124,11 +123,11 @@ defmodule Numbers do
assert 0 in range == ___
end

def is_range?(%Range{}), do: true
def is_range?(_), do: false
def range?(%Range{}), do: true
def range?(_), do: false

koan "Is this a range?" do
assert is_range?(1..10) == ___
assert is_range?(0) == ___
assert range?(1..10) == ___
assert range?(0) == ___
end
end
1 change: 0 additions & 1 deletion lib/koans/04_atoms.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Atoms do
@moduledoc false
use Koans

@intro "Atoms"
Expand Down
1 change: 0 additions & 1 deletion lib/koans/05_tuples.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Tuples do
@moduledoc false
use Koans

@intro "Tuples"
Expand Down
1 change: 0 additions & 1 deletion lib/koans/06_lists.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Lists do
@moduledoc false
use Koans

@intro "Lists"
Expand Down
1 change: 0 additions & 1 deletion lib/koans/07_keyword_lists.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule KeywordLists do
@moduledoc false
use Koans

@intro "KeywordLists"
Expand Down
1 change: 0 additions & 1 deletion lib/koans/08_maps.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Maps do
@moduledoc false
use Koans

@intro "Maps"
Expand Down
1 change: 0 additions & 1 deletion lib/koans/09_map_sets.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule MapSets do
@moduledoc false
use Koans

@intro "My name is Set, MapSet."
Expand Down
4 changes: 0 additions & 4 deletions lib/koans/10_structs.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
defmodule Structs do
@moduledoc false
use Koans

@intro "Structs"

defmodule Person do
@moduledoc false
defstruct [:name, :age]
end

Expand Down Expand Up @@ -37,12 +35,10 @@ defmodule Structs do
end

defmodule Plane do
@moduledoc false
defstruct passengers: 0, maker: :boeing
end

defmodule Airline do
@moduledoc false
defstruct plane: %Plane{}, name: "Southwest"
end

Expand Down
1 change: 0 additions & 1 deletion lib/koans/11_sigils.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Sigils do
@moduledoc false
use Koans

@intro "Sigils"
Expand Down
Loading