Class: Fdlint::Printer::ConsolePrinter

Inherits:
BasePrinter show all
Defined in:
lib/fdlint/printer/console_printer.rb

Instance Attribute Summary

Attributes inherited from BasePrinter

#file, #results, #source

Instance Method Summary collapse

Methods inherited from BasePrinter

#initialize, #post_validate

Constructor Details

This class inherits a constructor from Fdlint::Printer::BasePrinter

Instance Method Details

#log_text(entry) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fdlint/printer/console_printer.rb', line 52

def log_text( entry )
  level = entry.level.to_s.upcase.ljust(5)
  t = if entry.warn?
        level.yellow
      elsif entry.fatal?
        level.white_on_red
      elsif entry.error?
        level.red
      else
        level
      end
  if entry.row
    "[%s] %s %s" % [t, entry.pos, entry.message]
  else
    "[%s] %s" % [t, entry.message]
  end
end

#pre_validate(file) ⇒ Object



10
11
12
# File 'lib/fdlint/printer/console_printer.rb', line 10

def pre_validate( file )
  Kernel.print "\n---> reviewing " << file.to_s << " "
end


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fdlint/printer/console_printer.rb', line 14

def print( file, source, results )

  super
  
  if @results.empty?
    puts " [✔]\n".green
  else
    puts " [✗]\n".yellow

    @results.each do |r|
      print_log_entry r
    end
  end

end

#print_log_entry(entry) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fdlint/printer/console_printer.rb', line 30

def print_log_entry( entry )
  if entry.row && entry.row > 0
    col    = entry.column - 1
    row    = entry.row - 1
    left   = col - 50
    right  = col + 50
    left   = 0 if left < 0
    indent = ' ' * ( col - left )

    puts "     #{log_text entry}\n"
    if source
      puts "       #{source.lines.to_a[row][left..right].gsub(/\t/, ' ')}"
      puts "       #{indent}^"
    end
  else
    puts "     #{log_text entry}"
  end

  puts "\n"
end