Class: Koality::Reporter::Cane

Inherits:
Base
  • Object
show all
Defined in:
lib/koality/reporter/cane.rb

Instance Method Summary collapse

Methods inherited from Base

start

Instance Method Details

#columns_for_type(type, error) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/koality/reporter/cane.rb', line 39

def columns_for_type(type, error)
  case type
  when :abc
    ["#{color(error.detail, :red)}\n  #{error.file_name}", error.complexity]
  when :style
    ["#{color(error.message, :red)}\n  #{error.file_name}:#{error.line}"]
  when :threshold
    [color(error.name, :red), "expected: #{error.operator} #{color(error.limit, :green)}, actual: #{color(error.value, :red)}"]
  else
    error.columns
  end
end

#report(type, violations) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/koality/reporter/cane.rb', line 5

def report(type, violations)
  unless violations.count > 0
    report_success(type)
    return
  end

  show_table(type, violations)
end

#show_table(type, errors) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/koality/reporter/cane.rb', line 14

def show_table(type, errors)
  return if errors.empty?

  table = build_table
  table.title = color("Cane - #{type} - #{errors.count} Errors", :bold)

  if type == :style
    by_message = errors.group_by { |e| e.message.split(/\(\d+\)/).first }
    by_message.each do |message, errors|
      msg = color(message, :red)
      locations = errors.map { |e| "  #{e.file_name}:#{e.line}" }

      table.add_row ["#{msg}\n#{locations.join("\n")}", errors.count]
      table.add_row :separator unless message == by_message.keys.last
    end
  else
    errors.each do |error|
      table.add_row columns_for_type(type, error)
      table.add_row :separator unless error == errors.last
    end
  end

  puts table
end