diff --git a/lib/credo/cli/command/suggest/output/default.ex b/lib/credo/cli/command/suggest/output/default.ex index b3f9a63f4..21d49182b 100644 --- a/lib/credo/cli/command/suggest/output/default.ex +++ b/lib/credo/cli/command/suggest/output/default.ex @@ -31,6 +31,8 @@ defmodule Credo.CLI.Command.Suggest.Output.Default do @indent 8 @doc "Called before the analysis is run." + def print_before_info(_source_files, %Execution{format: "short"}), do: nil + def print_before_info(source_files, exec) do case Enum.count(source_files) do 0 -> @@ -54,22 +56,29 @@ defmodule Credo.CLI.Command.Suggest.Output.Default do @doc "Called after the analysis has run." def print_after_info(source_files, exec, time_load, time_run) do - term_width = Output.term_columns() + print_issue_list_by_category(source_files, exec, time_load, time_run) + print_summary(source_files, exec, time_load, time_run) + end - issues = Execution.get_issues(exec) + defp print_issue_list_by_category( + _source_files, + %Execution{format: "short"}, + _time_load, + _time_run + ), + do: nil - categories = - issues - |> Enum.map(& &1.category) - |> Enum.uniq() + defp print_issue_list_by_category(source_files, exec, _time_load, _time_run) do + term_width = Output.term_columns() + source_file_map = Enum.into(source_files, %{}, &{&1.filename, &1}) + issues = Execution.get_issues(exec) + categories = issues |> Enum.map(& &1.category) |> Enum.uniq() issue_map = Enum.into(categories, %{}, fn category -> {category, issues |> Enum.filter(&(&1.category == category))} end) - source_file_map = Enum.into(source_files, %{}, &{&1.filename, &1}) - categories |> Sorter.ensure(@category_starting_order, @category_ending_order) |> Enum.each(fn category -> @@ -81,9 +90,10 @@ defmodule Credo.CLI.Command.Suggest.Output.Default do term_width ) end) + end - source_files - |> Summary.print(exec, time_load, time_run) + defp print_summary(source_files, exec, time_load, time_run) do + Summary.print(source_files, exec, time_load, time_run) end defp print_issues_for_category( diff --git a/lib/credo/cli/output/summary.ex b/lib/credo/cli/output/summary.ex index a48c51f2d..fdb80d364 100644 --- a/lib/credo/cli/output/summary.ex +++ b/lib/credo/cli/output/summary.ex @@ -36,13 +36,11 @@ defmodule Credo.CLI.Output.Summary do source_file_count = exec |> Execution.get_source_files() |> Enum.count() checks_count = count_checks(exec) - UI.puts() - UI.puts([:faint, @cry_for_help]) - UI.puts() + print_cry_for_help(exec) + UI.puts([:faint, format_time_spent(checks_count, source_file_count, time_load, time_run)]) UI.puts(summary_parts(source_files, issues)) - UI.puts() print_priority_hint(exec) print_first_run_hint(exec) @@ -54,14 +52,30 @@ defmodule Credo.CLI.Output.Summary do defp print_first_run_hint(exec), do: exec + defp print_cry_for_help(%Execution{format: "short"}) do + nil + end + + defp print_cry_for_help(_exec) do + UI.puts() + UI.puts([:faint, @cry_for_help]) + UI.puts() + end + defp count_checks(exec) do {result, _only_matching, _ignore_matching} = Execution.checks(exec) Enum.count(result) end + defp print_priority_hint(%Execution{format: "short"}) do + nil + end + defp print_priority_hint(%Execution{min_priority: min_priority}) when min_priority >= 0 do + UI.puts() + UI.puts([ :faint, "Showing priority issues: ↑ ↗ → (use `mix credo explain` to explain issues, `mix credo --help` for options)." @@ -69,6 +83,8 @@ defmodule Credo.CLI.Output.Summary do end defp print_priority_hint(_) do + UI.puts() + UI.puts([ :faint, "Use `mix credo explain` to explain issues, `mix credo --help` for options."