From 1ac1ee6fdaaa1e069c1db5e3cd0e47f52dc70b91 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Tue, 23 Apr 2024 19:53:21 -0400 Subject: [PATCH 1/5] Fix deprecation for 1.17 1.17 deprecates calling remote functions without parentheses, which means that calls like `Foo.Bar.run` and `foo = %{bar: Foo}; foo.bar.run` should instead be formatted like `Foo.Bar.run()` and `foo = %{bar: Foo}; foo.bar.run()` This show up as runtime warnings. --- lib/credo/check/params.ex | 8 +++---- lib/credo/cli/output/formatter/sarif.ex | 22 +++++++++---------- lib/credo/cli/task/prepare_checks_to_run.ex | 2 +- lib/credo/cli/task/set_relevant_issues.ex | 2 +- .../execution/task/initialize_command.ex | 4 ++-- lib/credo/execution/task/parse_options.ex | 2 +- lib/credo/execution/task/validate_config.ex | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/credo/check/params.ex b/lib/credo/check/params.ex index 39df819cc..0998ce8d2 100644 --- a/lib/credo/check/params.ex +++ b/lib/credo/check/params.ex @@ -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 @@ -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 @@ -95,7 +95,7 @@ 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 diff --git a/lib/credo/cli/output/formatter/sarif.ex b/lib/credo/cli/output/formatter/sarif.ex index ef808c81e..50553d363 100644 --- a/lib/credo/cli/output/formatter/sarif.ex +++ b/lib/credo/cli/output/formatter/sarif.ex @@ -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) @@ -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" => %{ @@ -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 diff --git a/lib/credo/cli/task/prepare_checks_to_run.ex b/lib/credo/cli/task/prepare_checks_to_run.ex index 0da823497..b80f4ac34 100644 --- a/lib/credo/cli/task/prepare_checks_to_run.ex +++ b/lib/credo/cli/task/prepare_checks_to_run.ex @@ -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: [] diff --git a/lib/credo/cli/task/set_relevant_issues.ex b/lib/credo/cli/task/set_relevant_issues.ex index 51483f689..29f3aa00a 100644 --- a/lib/credo/cli/task/set_relevant_issues.ex +++ b/lib/credo/cli/task/set_relevant_issues.ex @@ -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) diff --git a/lib/credo/execution/task/initialize_command.ex b/lib/credo/execution/task/initialize_command.ex index a8e4bdbbb..329f5e8e9 100644 --- a/lib/credo/execution/task/initialize_command.ex +++ b/lib/credo/execution/task/initialize_command.ex @@ -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} @@ -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)} diff --git a/lib/credo/execution/task/parse_options.ex b/lib/credo/execution/task/parse_options.ex index b81be9ec0..18d7564f5 100644 --- a/lib/credo/execution/task/parse_options.ex +++ b/lib/credo/execution/task/parse_options.ex @@ -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 diff --git a/lib/credo/execution/task/validate_config.ex b/lib/credo/execution/task/validate_config.ex index 884309251..e8af47db7 100644 --- a/lib/credo/execution/task/validate_config.ex +++ b/lib/credo/execution/task/validate_config.ex @@ -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} -> From bf2b91e0bc3a13d46f6fc9ce99e0d6146a187057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Fri, 26 Apr 2024 16:12:54 +0200 Subject: [PATCH 2/5] Use .category() for checks --- lib/credo/cli/command/diff/output/default.ex | 2 +- lib/credo/cli/command/explain/explain_command.ex | 2 +- lib/credo/cli/command/explain/output/default.ex | 10 +++++----- lib/credo/cli/command/list/output/default.ex | 2 +- lib/credo/cli/command/suggest/output/default.ex | 2 +- lib/credo/cli/command/suggest/suggest_command.ex | 2 +- lib/credo/cli/output.ex | 6 +++--- lib/credo/cli/output/formatter/oneline.ex | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/credo/cli/command/diff/output/default.ex b/lib/credo/cli/command/diff/output/default.ex index 154a23f65..467e6e963 100644 --- a/lib/credo/cli/command/diff/output/default.ex +++ b/lib/credo/cli/command/diff/output/default.ex @@ -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, diff --git a/lib/credo/cli/command/explain/explain_command.ex b/lib/credo/cli/command/explain/explain_command.ex index b58167146..7483705c5 100644 --- a/lib/credo/cli/command/explain/explain_command.ex +++ b/lib/credo/cli/command/explain/explain_command.ex @@ -84,7 +84,7 @@ 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 diff --git a/lib/credo/cli/command/explain/output/default.ex b/lib/credo/cli/command/explain/output/default.ex index 75426b41e..490032284 100644 --- a/lib/credo/cli/command/explain/output/default.ex +++ b/lib/credo/cli/command/explain/output/default.ex @@ -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() @@ -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() @@ -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() diff --git a/lib/credo/cli/command/list/output/default.ex b/lib/credo/cli/command/list/output/default.ex index dd624d3b1..fe85fe8b2 100644 --- a/lib/credo/cli/command/list/output/default.ex +++ b/lib/credo/cli/command/list/output/default.ex @@ -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, diff --git a/lib/credo/cli/command/suggest/output/default.ex b/lib/credo/cli/command/suggest/output/default.ex index 21d49182b..60f4ed917 100644 --- a/lib/credo/cli/command/suggest/output/default.ex +++ b/lib/credo/cli/command/suggest/output/default.ex @@ -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, diff --git a/lib/credo/cli/command/suggest/suggest_command.ex b/lib/credo/cli/command/suggest/suggest_command.ex index d67a41710..0f6a95727 100644 --- a/lib/credo/cli/command/suggest/suggest_command.ex +++ b/lib/credo/cli/command/suggest/suggest_command.ex @@ -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)} diff --git a/lib/credo/cli/output.ex b/lib/credo/cli/output.ex index d85300ac4..cf7fad119 100644 --- a/lib/credo/cli/output.ex +++ b/lib/credo/cli/output.ex @@ -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 @@ -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 diff --git a/lib/credo/cli/output/formatter/oneline.ex b/lib/credo/cli/output/formatter/oneline.ex index 9c51ce371..14c656aa1 100644 --- a/lib/credo/cli/output/formatter/oneline.ex +++ b/lib/credo/cli/output/formatter/oneline.ex @@ -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(), " ", From 7098a9fd522323b1e73cf05aee664c28e88bb2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Fri, 26 Apr 2024 16:14:40 +0200 Subject: [PATCH 3/5] Use .base_priority() for checks --- lib/credo/cli/command/explain/explain_command.ex | 2 +- lib/credo/cli/task/prepare_checks_to_run.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/credo/cli/command/explain/explain_command.ex b/lib/credo/cli/command/explain/explain_command.ex index 7483705c5..914689aca 100644 --- a/lib/credo/cli/command/explain/explain_command.ex +++ b/lib/credo/cli/command/explain/explain_command.ex @@ -87,7 +87,7 @@ defmodule Credo.CLI.Command.Explain.ExplainCommand do category: check.category(), check: check, explanation_for_issue: check.explanation, - priority: check.base_priority + priority: check.base_priority() } end end diff --git a/lib/credo/cli/task/prepare_checks_to_run.ex b/lib/credo/cli/task/prepare_checks_to_run.ex index b80f4ac34..97e8d5847 100644 --- a/lib/credo/cli/task/prepare_checks_to_run.ex +++ b/lib/credo/cli/task/prepare_checks_to_run.ex @@ -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 From 46d4bf8ae669777faa2d87584d4ba32475e24036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Fri, 26 Apr 2024 16:17:44 +0200 Subject: [PATCH 4/5] Use .tags() for checks --- lib/credo/check/params.ex | 2 +- lib/credo/execution.ex | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/credo/check/params.ex b/lib/credo/check/params.ex index 0998ce8d2..08ca4fa4f 100644 --- a/lib/credo/check/params.ex +++ b/lib/credo/check/params.ex @@ -100,6 +100,6 @@ defmodule Credo.Check.Params do @doc false def tags(params, check_mod) do - params[:__tags__] || params[:tags] || check_mod.tags + params[:__tags__] || params[:tags] || check_mod.tags() end end diff --git a/lib/credo/execution.ex b/lib/credo/execution.ex index 3e9750f9a..a621cb771 100644 --- a/lib/credo/execution.ex +++ b/lib/credo/execution.ex @@ -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 From 8e8808a53846cccc801ef8da8292d4cc7ac78ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Fri, 26 Apr 2024 16:18:46 +0200 Subject: [PATCH 5/5] Use .explanation() for checks --- lib/credo/cli/command/explain/explain_command.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/credo/cli/command/explain/explain_command.ex b/lib/credo/cli/command/explain/explain_command.ex index 914689aca..bcbdd4880 100644 --- a/lib/credo/cli/command/explain/explain_command.ex +++ b/lib/credo/cli/command/explain/explain_command.ex @@ -86,7 +86,7 @@ defmodule Credo.CLI.Command.Explain.ExplainCommand do %{ category: check.category(), check: check, - explanation_for_issue: check.explanation, + explanation_for_issue: check.explanation(), priority: check.base_priority() } end @@ -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,