Skip to content

Commit

Permalink
allow strict behaviour for --exit-code
Browse files Browse the repository at this point in the history
  • Loading branch information
amatalai committed Jul 30, 2017
1 parent dea7e06 commit f1b1620
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions lib/pronto/credo/output_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,43 @@ module Pronto
module Credo
class OutputParser
attr_reader :output, :file
TYPE_WARNINGS = { 'R' => :info,
'W' => :warning,
'C' => :info,
'D' => :info,
'F' => :info,
'A' => :info
}

def initialize(file, output)
@file = file
@output = output
end

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

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_level = type_warnings[line_parts[2].strip]
offence_message = line_parts[3..-1].join(':').strip
else
offence_level = TYPE_WARNINGS[line_parts[3].strip]
offence_level = type_warnings[line_parts[3].strip]
column_line = line_parts[2].to_i
offence_message = line_parts[4..-1].join(':').strip
end
Expand Down

0 comments on commit f1b1620

Please sign in to comment.