Refactor ExplainFormatter a bit

This commit is contained in:
Sijawusz Pur Rahnama 2023-07-13 02:12:59 +02:00
parent c9538220c6
commit 1718945523

View file

@ -4,8 +4,6 @@ module Ameba::Formatter
# A formatter that shows the detailed explanation of the issue at
# a specific location.
class ExplainFormatter
HEADING_MARKER = "## "
include Util
getter output : IO::FileDescriptor | IO::Memory
@ -64,10 +62,7 @@ module Ameba::Formatter
rule.name.colorize(:magenta),
rule.severity.to_s.colorize(rule.severity.color),
}
if rule.responds_to?(:description)
output_paragraph rule.description
end
output_paragraph rule.description
rule_doc = colorize_code_fences(rule.class.parsed_doc)
return unless rule_doc
@ -84,7 +79,7 @@ module Ameba::Formatter
end
private def output_title(title)
output << HEADING_MARKER.colorize(:yellow)
output << "### ".colorize(:yellow)
output << title.upcase.colorize(:yellow)
output << "\n\n"
end
@ -95,7 +90,7 @@ module Ameba::Formatter
private def output_paragraph(paragraph : Array)
paragraph.each do |line|
output << ' ' << line << '\n'
output << " " << line << '\n'
end
output << '\n'
end