Skip to content

Commit

Permalink
Add 'short' output format
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene committed Jan 30, 2024
1 parent ac76775 commit cf88086
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
30 changes: 20 additions & 10 deletions lib/credo/cli/command/suggest/output/default.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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 ->
Expand All @@ -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(
Expand Down
24 changes: 20 additions & 4 deletions lib/credo/cli/output/summary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -54,21 +52,39 @@ 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)."
])
end

defp print_priority_hint(_) do
UI.puts()

UI.puts([
:faint,
"Use `mix credo explain` to explain issues, `mix credo --help` for options."
Expand Down

0 comments on commit cf88086

Please sign in to comment.