lib/goodcheck/reporters/text.rb in goodcheck-3.0.3 vs lib/goodcheck/reporters/text.rb in goodcheck-3.1.0
- old
+ new
@@ -23,11 +23,20 @@
end
def issue(issue)
@issue_count += 1
- message = issue.rule.message.lines.first.chomp
+ format_line = lambda do |line:, column:|
+ format_args = {
+ path: Rainbow(issue.path).cyan,
+ location: Rainbow(":#{line}:#{column}:").dimgray,
+ message: issue.rule.message.lines.first.chomp,
+ rule: Rainbow("(#{issue.rule.id})").dimgray,
+ severity: issue.rule.severity ? Rainbow("[#{issue.rule.severity}]").magenta : ""
+ }
+ format("%<path>s%<location>s %<message>s %<rule>s %<severity>s", format_args).strip
+ end
if issue.location
start_line = issue.location.start_line
start_column = issue.location.start_column
start_column_index = start_column - 1
@@ -35,16 +44,24 @@
column_size = if issue.location.one_line?
issue.location.column_size
else
line.bytesize - start_column
end
- rule = Rainbow("(#{issue.rule.id})").darkgray
- severity = issue.rule.severity ? Rainbow("[#{issue.rule.severity}]").magenta : ""
- stdout.puts "#{Rainbow(issue.path).cyan}:#{start_line}:#{start_column}: #{message} #{rule} #{severity}".strip
+ stdout.puts format_line.call(line: start_line, column: start_column)
stdout.puts line.chomp
stdout.puts (" " * start_column_index) + Rainbow("^" + "~" * (column_size - 1)).yellow
else
- stdout.puts "#{Rainbow(issue.path).cyan}:-:-: #{message}"
+ stdout.puts format_line.call(line: "-", column: "-")
+ end
+
+ justifications = issue.rule.justifications
+ unless justifications.empty?
+ stdout.puts ""
+ stdout.puts " #{Rainbow('Justifications').dimgray.underline.italic}:"
+ justifications.each do |justification|
+ stdout.puts " • #{Rainbow(justification).dimgray.italic}"
+ end
+ stdout.puts ""
end
end
def summary
files = case @file_count