class Pronto::Credo::OutputParser

Attributes

file[R]
output[R]

Public Class Methods

new(file, output) click to toggle source
# File lib/pronto/credo/output_parser.rb, line 6
def initialize(file, output)
  @file = file
  @output = output
end

Public Instance Methods

parse() click to toggle source
# File lib/pronto/credo/output_parser.rb, line 31
def parse
  output.lines.map do |line|
    line_parts = line.split(':')
    next unless file.start_with?(line_parts[0])
    offence_in_line = line_parts[1]
    column_line = nil
    if line_parts[2].to_i == 0
      offence_level = type_warnings[line_parts[2].strip]
      offence_message = line_parts[3..-1].join(':').strip
    else
      offence_level = type_warnings[line_parts[3].strip]
      column_line = line_parts[2].to_i
      offence_message = line_parts[4..-1].join(':').strip
    end
    {
      line: offence_in_line.to_i,
      column: column_line,
      level: offence_level,
      message: offence_message
    }
  end.compact
end
type_warnings() click to toggle source
# File lib/pronto/credo/output_parser.rb, line 11
def type_warnings
  @type_warnings ||= if ENV["PRONTO_CREDO_STRICT"] == "1"
    { 'R' => :warning,
      'W' => :warning,
      'C' => :warning,
      'D' => :warning,
      'F' => :warning,
      'A' => :warning
    }
  else
    { 'R' => :info,
      'W' => :warning,
      'C' => :info,
      'D' => :info,
      'F' => :info,
      'A' => :info
    }
  end
end