Skip to content

Commit

Permalink
Merge branch 'mhanberg-fix-deprecatoins'
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene committed Apr 29, 2024
2 parents e48a5eb + 8e8808a commit 35abc4d
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 43 deletions.
10 changes: 5 additions & 5 deletions lib/credo/check/params.ex
Expand Up @@ -36,7 +36,7 @@ defmodule Credo.Check.Params do
def get(params, field, check_mod) do
case params[field] do
nil ->
check_mod.param_defaults[field]
check_mod.param_defaults()[field]

val ->
val
Expand Down Expand Up @@ -71,12 +71,12 @@ defmodule Credo.Check.Params do

@doc false
def category(params, check_mod) do
params[:__category__] || params[:category] || check_mod.category
params[:__category__] || params[:category] || check_mod.category()
end

@doc false
def exit_status(params, check_mod) do
params[:__exit_status__] || params[:exit_status] || check_mod.exit_status
params[:__exit_status__] || params[:exit_status] || check_mod.exit_status()
end

@doc false
Expand All @@ -95,11 +95,11 @@ defmodule Credo.Check.Params do

@doc false
def priority(params, check_mod) do
params[:__priority__] || params[:priority] || check_mod.base_priority
params[:__priority__] || params[:priority] || check_mod.base_priority()
end

@doc false
def tags(params, check_mod) do
params[:__tags__] || params[:tags] || check_mod.tags
params[:__tags__] || params[:tags] || check_mod.tags()
end
end
2 changes: 1 addition & 1 deletion lib/credo/cli/command/diff/output/default.ex
Expand Up @@ -316,7 +316,7 @@ defmodule Credo.CLI.Command.Diff.Output.Default do
UI.edge(outer_color),
outer_color,
tag_style,
Output.check_tag(check.category),
Output.check_tag(check.category()),
" ",
priority |> Output.priority_arrow(),
:normal,
Expand Down
8 changes: 4 additions & 4 deletions lib/credo/cli/command/explain/explain_command.ex
Expand Up @@ -84,10 +84,10 @@ defmodule Credo.CLI.Command.Explain.ExplainCommand do

defp cast_to_explanation(check) do
%{
category: check.category,
category: check.category(),
check: check,
explanation_for_issue: check.explanation,
priority: check.base_priority
explanation_for_issue: check.explanation(),
priority: check.base_priority()
}
end
end
Expand Down Expand Up @@ -181,7 +181,7 @@ defmodule Credo.CLI.Command.Explain.ExplainCommand do
category: issue.category,
check: issue.check,
column: issue.column,
explanation_for_issue: issue.check.explanation,
explanation_for_issue: issue.check.explanation(),
filename: issue.filename,
line_no: issue.line_no,
message: issue.message,
Expand Down
10 changes: 5 additions & 5 deletions lib/credo/cli/command/explain/output/default.ex
Expand Up @@ -52,7 +52,7 @@ defmodule Credo.CLI.Command.Explain.Output.Default do
term_width
) do
check_name = check |> to_string |> String.replace(~r/^Elixir\./, "")
color = Output.check_color(check.category)
color = Output.check_color(check.category())

UI.puts()

Expand Down Expand Up @@ -84,9 +84,9 @@ defmodule Credo.CLI.Command.Explain.Output.Default do
inner_color,
tag_style,
" ",
Output.check_tag(check.category),
Output.check_tag(check.category()),
:reset,
" Category: #{check.category} "
" Category: #{check.category()} "
]
|> UI.puts()

Expand Down Expand Up @@ -189,9 +189,9 @@ defmodule Credo.CLI.Command.Explain.Output.Default do
inner_color,
tag_style,
" ",
Output.check_tag(check.category),
Output.check_tag(check.category()),
:reset,
" Category: #{check.category} "
" Category: #{check.category()} "
]
|> UI.puts()

Expand Down
2 changes: 1 addition & 1 deletion lib/credo/cli/command/list/output/default.ex
Expand Up @@ -102,7 +102,7 @@ defmodule Credo.CLI.Command.List.Output.Default do
UI.edge(outer_color),
inner_color,
tag_style,
Output.check_tag(check.category),
Output.check_tag(check.category()),
" ",
priority |> Output.priority_arrow(),
:normal,
Expand Down
2 changes: 1 addition & 1 deletion lib/credo/cli/command/suggest/output/default.ex
Expand Up @@ -250,7 +250,7 @@ defmodule Credo.CLI.Command.Suggest.Output.Default do
UI.edge(outer_color),
outer_color,
tag_style,
Output.check_tag(check.category),
Output.check_tag(check.category()),
" ",
priority |> Output.priority_arrow(),
:normal,
Expand Down
2 changes: 1 addition & 1 deletion lib/credo/cli/command/suggest/suggest_command.ex
Expand Up @@ -115,7 +115,7 @@ defmodule Credo.CLI.Command.Suggest.SuggestCommand do
def modify_config_to_only_include_needed_checks(%Credo.Execution{} = exec, files_that_changed) do
checks =
Enum.map(exec.checks, fn {check, params} ->
if check.category == :consistency do
if check.category() == :consistency do
{check, params}
else
{check, Params.put_rerun_files_that_changed(params, files_that_changed)}
Expand Down
6 changes: 3 additions & 3 deletions lib/credo/cli/output.ex
Expand Up @@ -33,7 +33,7 @@ defmodule Credo.CLI.Output do
end

def check_tag(check_mod, in_parens) do
check_mod.category
check_mod.category()
|> to_string
|> check_tag(in_parens)
end
Expand All @@ -55,8 +55,8 @@ defmodule Credo.CLI.Output do
|> check_color
end

def check_color(check_mod) do
check_mod.category
def check_color(%{} = issue_or_map) do
issue_or_map.category
|> to_string
|> check_color
end
Expand Down
2 changes: 1 addition & 1 deletion lib/credo/cli/output/formatter/oneline.ex
Expand Up @@ -28,7 +28,7 @@ defmodule Credo.CLI.Output.Formatter.Oneline do

[
inner_color,
Output.check_tag(check.category),
Output.check_tag(check.category()),
" ",
priority |> Output.priority_arrow(),
" ",
Expand Down
22 changes: 11 additions & 11 deletions lib/credo/cli/output/formatter/sarif.ex
Expand Up @@ -17,21 +17,21 @@ defmodule Credo.CLI.Output.Formatter.SARIF do

final_rules =
issues
|> Enum.uniq_by(& &1.check.id)
|> Enum.uniq_by(& &1.check.id())
|> Enum.map(fn issue ->
%{
"id" => issue.check.id,
"id" => issue.check.id(),
"name" => Credo.Code.Name.full(issue.check),
"fullDescription" => %{
"text" => issue.check.explanation |> String.replace("`", "'"),
"markdown" => issue.check.explanation
"text" => issue.check.explanation() |> String.replace("`", "'"),
"markdown" => issue.check.explanation()
},
"properties" => %{
"tags" => [
issue.category
]
},
"helpUri" => issue.check.docs_uri
"helpUri" => issue.check.docs_uri()
}
end)

Expand Down Expand Up @@ -158,21 +158,21 @@ defmodule Credo.CLI.Output.Formatter.SARIF do

rule_and_issue = {
%{
"id" => issue.check.id,
"id" => issue.check.id(),
"name" => Credo.Code.Name.full(issue.check),
"fullDescription" => %{
"text" => issue.check.explanation |> String.replace("`", "'"),
"markdown" => issue.check.explanation
"text" => issue.check.explanation() |> String.replace("`", "'"),
"markdown" => issue.check.explanation()
},
"properties" => %{
"tags" => [
issue.category
]
},
"helpUri" => issue.check.docs_uri
"helpUri" => issue.check.docs_uri()
},
%{
"ruleId" => issue.check.id,
"ruleId" => issue.check.id(),
"level" => sarif_level,
"rank" => priority_to_sarif_rank(issue.priority),
"message" => %{
Expand Down Expand Up @@ -208,7 +208,7 @@ defmodule Credo.CLI.Output.Formatter.SARIF do
rule_and_issue
|> remove_nil_endcolumn(!column_end)
|> remove_warning_level(sarif_level == :warning)
|> remove_redundant_name(issue.check.id == Credo.Code.Name.full(issue.check))
|> remove_redundant_name(issue.check.id() == Credo.Code.Name.full(issue.check))
end

defp remove_nil_endcolumn(sarif, false), do: sarif
Expand Down
4 changes: 2 additions & 2 deletions lib/credo/cli/task/prepare_checks_to_run.ex
Expand Up @@ -49,7 +49,7 @@ defmodule Credo.CLI.Task.PrepareChecksToRun do
Enum.reject(exec.checks.enabled, fn
# deprecated
{check} ->
Credo.Priority.to_integer(check.base_priority) < below_priority
Credo.Priority.to_integer(check.base_priority()) < below_priority

{_check, false} ->
true
Expand Down Expand Up @@ -83,7 +83,7 @@ defmodule Credo.CLI.Task.PrepareChecksToRun do
end

defp matches_requirement?({check}, elixir_version) do
Version.match?(elixir_version, check.elixir_version)
Version.match?(elixir_version, check.elixir_version())
end

defp to_match_regexes(nil), do: []
Expand Down
2 changes: 1 addition & 1 deletion lib/credo/cli/task/set_relevant_issues.ex
Expand Up @@ -12,7 +12,7 @@ defmodule Credo.CLI.Task.SetRelevantIssues do
|> Filter.important(exec)
|> Filter.valid_issues(exec)
|> Enum.sort_by(fn issue ->
{issue.check.id, issue.filename, issue.line_no}
{issue.check.id(), issue.filename, issue.line_no}
end)

put_issues(exec, issues)
Expand Down
6 changes: 3 additions & 3 deletions lib/credo/execution.ex
Expand Up @@ -255,14 +255,14 @@ defmodule Credo.Execution do
"""
def tags_for_check(check, params)

def tags_for_check(check, nil), do: check.tags
def tags_for_check(check, []), do: check.tags
def tags_for_check(check, nil), do: check.tags()
def tags_for_check(check, []), do: check.tags()

def tags_for_check(check, params) when is_list(params) do
params
|> Credo.Check.Params.tags(check)
|> Enum.flat_map(fn
:__initial__ -> check.tags
:__initial__ -> check.tags()
tag -> [tag]
end)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/credo/execution/task/initialize_command.ex
Expand Up @@ -22,7 +22,7 @@ defmodule Credo.Execution.Task.InitializeCommand do
end

defp cli_options_switches(command_mod) do
command_mod.cli_switches
command_mod.cli_switches()
|> List.wrap()
|> Enum.map(fn
%{name: name, type: type} when is_binary(name) -> {String.to_atom(name), type}
Expand All @@ -31,7 +31,7 @@ defmodule Credo.Execution.Task.InitializeCommand do
end

defp cli_options_aliases(command_mod) do
command_mod.cli_switches
command_mod.cli_switches()
|> List.wrap()
|> Enum.map(fn
%{name: name, alias: alias} when is_binary(name) -> {alias, String.to_atom(name)}
Expand Down
2 changes: 1 addition & 1 deletion lib/credo/execution/task/parse_options.ex
Expand Up @@ -30,7 +30,7 @@ defmodule Credo.Execution.Task.ParseOptions do
command_name = Execution.get_command_name(exec)
command_mod = Execution.get_command(exec, command_name)

command_mod.treat_unknown_args_as_files?
command_mod.treat_unknown_args_as_files?()
else
false
end
Expand Down
2 changes: 1 addition & 1 deletion lib/credo/execution/task/validate_config.ex
Expand Up @@ -67,7 +67,7 @@ defmodule Credo.Execution.Task.ValidateConfig do
end

defp do_warn_if_check_params_invalid({check, params}) do
valid_param_names = check.param_names ++ Params.builtin_param_names()
valid_param_names = check.param_names() ++ Params.builtin_param_names()
check = check |> to_string |> String.to_existing_atom()

Enum.each(params, fn {param_name, _param_value} ->
Expand Down

0 comments on commit 35abc4d

Please sign in to comment.