Skip to content
Permalink
Browse files

Pass __MODULE__ to Params.get/3

  • Loading branch information
rrrene committed Feb 13, 2020
1 parent 18c504c commit c263274b2fbdc6eb72e7eb8a7f2842aee4e875bd
@@ -29,7 +29,7 @@ defmodule <%= @check_name %> do
# we use the `params` parameter and the `Params` module to extract a
# configuration parameter from `.credo.exs` while also providing a
# default value
line_regex = params |> Params.get(:regex, @default_params)
line_regex = params |> Params.get(:regex, __MODULE__)

# Finally, we can run our custom made analysis.
# In this example, we look for lines in source code matching our regex:
@@ -69,7 +69,7 @@ defmodule Credo.Check.Consistency.SpaceAroundOperators do
end

defp ignored?(location, params) do
ignored_triggers = Params.get(params, :ignore, @default_params)
ignored_triggers = Params.get(params, :ignore, __MODULE__)

Enum.member?(ignored_triggers, location[:trigger])
end
@@ -38,7 +38,7 @@ defmodule Credo.Check.Consistency.SpaceInParentheses do

defp issues_for(expected, source_file, params) do
issue_meta = IssueMeta.for(source_file, params)
allow_empty_enums = Params.get(params, :allow_empty_enums, @default_params)
allow_empty_enums = Params.get(params, :allow_empty_enums, __MODULE__)

lines_with_issues =
@collector.find_locations_not_matching(expected, source_file, allow_empty_enums)
@@ -70,13 +70,13 @@ defmodule Credo.Check.Design.AliasUsage do
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)

excluded_namespaces = Params.get(params, :excluded_namespaces, @default_params)
excluded_namespaces = Params.get(params, :excluded_namespaces, __MODULE__)

excluded_lastnames = Params.get(params, :excluded_lastnames, @default_params)
excluded_lastnames = Params.get(params, :excluded_lastnames, __MODULE__)

if_nested_deeper_than = Params.get(params, :if_nested_deeper_than, @default_params)
if_nested_deeper_than = Params.get(params, :if_nested_deeper_than, __MODULE__)

if_called_more_often_than = Params.get(params, :if_called_more_often_than, @default_params)
if_called_more_often_than = Params.get(params, :if_called_more_often_than, __MODULE__)

source_file
|> Credo.Code.prewalk(&traverse(&1, &2, issue_meta, excluded_namespaces, excluded_lastnames))
@@ -40,8 +40,8 @@ defmodule Credo.Check.Design.DuplicatedCode do

@doc false
def run(source_files, exec, params \\ []) when is_list(source_files) do
mass_threshold = Params.get(params, :mass_threshold, @default_params)
nodes_threshold = Params.get(params, :nodes_threshold, @default_params)
mass_threshold = Params.get(params, :mass_threshold, __MODULE__)
nodes_threshold = Params.get(params, :nodes_threshold, __MODULE__)

source_files
|> duplicate_nodes(mass_threshold)
@@ -33,7 +33,7 @@ defmodule Credo.Check.Design.TagFIXME do
@doc false
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)
include_doc? = Params.get(params, :include_doc, @default_params)
include_doc? = Params.get(params, :include_doc, __MODULE__)

source_file
|> TagHelper.tags(@tag_name, include_doc?)
@@ -33,7 +33,7 @@ defmodule Credo.Check.Design.TagTODO do
@doc false
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)
include_doc? = Params.get(params, :include_doc, @default_params)
include_doc? = Params.get(params, :include_doc, __MODULE__)

source_file
|> TagHelper.tags(@tag_name, include_doc?)
@@ -14,10 +14,10 @@ defmodule Credo.Check.Params do
iex> Credo.Check.Params.get([foo: "baz"], :foo, [foo: "bar"])
"baz"
"""
def get(params, field, default_params \\ []) when is_list(params) do
def get(params, field, check_mod) do
case params[field] do
nil ->
default_params[field]
check_mod.params_defaults[field]

val ->
val
@@ -29,7 +29,7 @@ defmodule Credo.Check.Readability.LargeNumbers do
@doc false
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)
min_number = Params.get(params, :only_greater_than, @default_params)
min_number = Params.get(params, :only_greater_than, __MODULE__)

source_file
|> Credo.Code.to_tokens()
@@ -35,14 +35,14 @@ defmodule Credo.Check.Readability.MaxLineLength do
@doc false
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)
max_length = Params.get(params, :max_length, @default_params)
max_length = Params.get(params, :max_length, __MODULE__)

ignore_definitions = Params.get(params, :ignore_definitions, @default_params)
ignore_definitions = Params.get(params, :ignore_definitions, __MODULE__)

ignore_specs = Params.get(params, :ignore_specs, @default_params)
ignore_strings = Params.get(params, :ignore_strings, @default_params)
ignore_heredocs = Params.get(params, :ignore_heredocs, @default_params)
ignore_urls = Params.get(params, :ignore_urls, @default_params)
ignore_specs = Params.get(params, :ignore_specs, __MODULE__)
ignore_strings = Params.get(params, :ignore_strings, __MODULE__)
ignore_heredocs = Params.get(params, :ignore_heredocs, __MODULE__)
ignore_urls = Params.get(params, :ignore_urls, __MODULE__)

definitions = Credo.Code.prewalk(source_file, &find_definitions/2)
specs = Credo.Code.prewalk(source_file, &find_specs/2)
@@ -54,7 +54,7 @@ defmodule Credo.Check.Readability.ModuleDoc do
[]
else
issue_meta = IssueMeta.for(source_file, params)
ignore_names = Params.get(params, :ignore_names, @default_params)
ignore_names = Params.get(params, :ignore_names, __MODULE__)

{_continue, issues} =
Credo.Code.prewalk(
@@ -33,7 +33,7 @@ defmodule Credo.Check.Readability.ParenthesesOnZeroArityDefs do

@doc false
def run(source_file, params \\ []) do
parens? = Params.get(params, :parens, @default_params)
parens? = Params.get(params, :parens, __MODULE__)
issue_meta = IssueMeta.for(source_file, params)

Credo.Code.prewalk(source_file, &traverse(&1, &2, issue_meta, parens?))
@@ -29,7 +29,7 @@ defmodule Credo.Check.Readability.RedundantBlankLines do
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)

max_blank_lines = Params.get(params, :max_blank_lines, @default_params)
max_blank_lines = Params.get(params, :max_blank_lines, __MODULE__)

source_file
|> Charlists.replace_with_spaces("=")
@@ -40,7 +40,7 @@ defmodule Credo.Check.Readability.StringSigils do
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)

maximum_allowed_quotes = Params.get(params, :maximum_allowed_quotes, @default_params)
maximum_allowed_quotes = Params.get(params, :maximum_allowed_quotes, __MODULE__)

case remove_heredocs_and_convert_to_ast(source_file) do
{:ok, ast} ->
@@ -25,7 +25,7 @@ defmodule Credo.Check.Readability.TrailingWhiteSpace do
@doc false
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)
ignore_strings = Params.get(params, :ignore_strings, @default_params)
ignore_strings = Params.get(params, :ignore_strings, __MODULE__)

source_file
|> to_lines(ignore_strings)
@@ -34,8 +34,8 @@ defmodule Credo.Check.Refactor.ABCSize do
def run(source_file, params \\ []) do
ignore_ecto? = imports_ecto_query?(source_file)
issue_meta = IssueMeta.for(source_file, params)
max_abc_size = Params.get(params, :max_size, @default_params)
excluded_functions = Params.get(params, :excluded_functions, @default_params)
max_abc_size = Params.get(params, :max_size, __MODULE__)
excluded_functions = Params.get(params, :excluded_functions, __MODULE__)

excluded_functions =
if ignore_ecto? do
@@ -43,7 +43,7 @@ defmodule Credo.Check.Refactor.CyclomaticComplexity do
@doc false
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)
max_complexity = Params.get(params, :max_complexity, @default_params)
max_complexity = Params.get(params, :max_complexity, __MODULE__)

Credo.Code.prewalk(
source_file,
@@ -24,8 +24,8 @@ defmodule Credo.Check.Refactor.FunctionArity do
@doc false
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)
max_arity = Params.get(params, :max_arity, @default_params)
ignore_defp = Params.get(params, :ignore_defp, @default_params)
max_arity = Params.get(params, :max_arity, __MODULE__)
ignore_defp = Params.get(params, :ignore_defp, __MODULE__)

Credo.Code.prewalk(
source_file,
@@ -79,8 +79,8 @@ defmodule Credo.Check.Refactor.LongQuoteBlocks do
@doc false
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)
max_line_count = Params.get(params, :max_line_count, @default_params)
ignore_comments = Params.get(params, :ignore_comments, @default_params)
max_line_count = Params.get(params, :max_line_count, __MODULE__)
ignore_comments = Params.get(params, :ignore_comments, __MODULE__)

Credo.Code.prewalk(
source_file,
@@ -34,10 +34,10 @@ defmodule Credo.Check.Refactor.ModuleDependencies do
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)

max_deps = Params.get(params, :max_deps, @default_params)
dependency_namespaces = Params.get(params, :dependency_namespaces, @default_params)
excluded_namespaces = Params.get(params, :excluded_namespaces, @default_params)
excluded_paths = Params.get(params, :excluded_paths, @default_params)
max_deps = Params.get(params, :max_deps, __MODULE__)
dependency_namespaces = Params.get(params, :dependency_namespaces, __MODULE__)
excluded_namespaces = Params.get(params, :excluded_namespaces, __MODULE__)
excluded_paths = Params.get(params, :excluded_paths, __MODULE__)

case ignore_path?(source_file.filename, excluded_paths) do
true ->
@@ -37,7 +37,7 @@ defmodule Credo.Check.Refactor.Nesting do
@doc false
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)
max_nesting = Params.get(params, :max_nesting, @default_params)
max_nesting = Params.get(params, :max_nesting, __MODULE__)

Credo.Code.prewalk(source_file, &traverse(&1, &2, issue_meta, max_nesting))
end
@@ -43,7 +43,7 @@ defmodule Credo.Check.Refactor.PerceivedComplexity do
@doc false
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)
max_complexity = Params.get(params, :max_complexity, @default_params)
max_complexity = Params.get(params, :max_complexity, __MODULE__)

Credo.Code.prewalk(
source_file,
@@ -38,9 +38,9 @@ defmodule Credo.Check.Refactor.PipeChainStart do
def run(source_file, params \\ []) do
issue_meta = IssueMeta.for(source_file, params)

excluded_functions = Params.get(params, :excluded_functions, @default_params)
excluded_functions = Params.get(params, :excluded_functions, __MODULE__)

excluded_argument_types = Params.get(params, :excluded_argument_types, @default_params)
excluded_argument_types = Params.get(params, :excluded_argument_types, __MODULE__)

Credo.Code.prewalk(
source_file,
@@ -90,7 +90,7 @@ defmodule Credo.Check.Warning.LazyLogging do

defp find_issue(fun_name, arguments, meta, issue_meta) do
params = IssueMeta.params(issue_meta)
ignored_functions = Params.get(params, :ignore, @default_params)
ignored_functions = Params.get(params, :ignore, __MODULE__)

unless Enum.member?(ignored_functions, fun_name) do
issue_for_call(arguments, meta, issue_meta)
@@ -25,7 +25,7 @@ defmodule Credo.Check.Warning.MixEnv do

@doc false
def run(%SourceFile{filename: filename} = source_file, params \\ []) do
excluded_paths = Params.get(params, :excluded_paths, @default_params)
excluded_paths = Params.get(params, :excluded_paths, __MODULE__)

case ignore_path?(source_file.filename, excluded_paths) do
true ->

0 comments on commit c263274

Please sign in to comment.
You can’t perform that action at this time.