class Lintron::TerminalReporter

Outputs lint results on the command line

Public Instance Methods

colors() click to toggle source
# File lib/lintron/terminal_reporter.rb, line 44
def colors
  @_colors ||= [:magenta, :cyan].cycle.each
end
do_line(violation, last_file, row_header_width) click to toggle source
# File lib/lintron/terminal_reporter.rb, line 26
def do_line(violation, last_file, row_header_width)
  rule = ''
  if last_file != violation.path
    colors.rewind
    rule += hr
  end

  file_and_line = violation.file_and_line(row_header_width)
  rule + wrap_pretty(
    "#{file_and_line}#{violation['message']}".colorize(colors.next),
    file_and_line.length,
  )
end
format_violations(violations) click to toggle source
# File lib/lintron/terminal_reporter.rb, line 8
def format_violations(violations)
  row_header_width = violations.map { |v| v.file_and_line.length }.max
  return no_violations if violations.empty?
  last_file = violations.first.path
  buffer = ''

  violations.each do |violation|
    buffer += do_line(violation, last_file, row_header_width)
    last_file = violation.path
  end
  buffer += "\n\n"
  buffer
end
hr() click to toggle source
# File lib/lintron/terminal_reporter.rb, line 40
def hr
  '-' * TermInfo.screen_size[1] + "\n\n\n"
end
no_violations() click to toggle source
# File lib/lintron/terminal_reporter.rb, line 22
def no_violations
  'No violations found!'.colorize(:green)
end
wrap_pretty(string, indent_level) click to toggle source
# File lib/lintron/terminal_reporter.rb, line 48
def wrap_pretty(string, indent_level)
  width = TermInfo.screen_size[1] # Get the width of the term
  buffer = ''
  words = string.split(/\s/)

  current_word = 0
  line_length = 0
  last_line_word = 0
  while current_word < words.length
    line_length += words[current_word].length
    if line_length > width - 5 - indent_level &&
       current_word > last_line_word

      buffer += "\n"
      buffer += ' ' * indent_level
      line_length = indent_level
      last_line_word = current_word
    else
      buffer += words[current_word]
      buffer += ' '
      current_word += 1
    end
  end
  buffer + "\n"
end