Class: Pronto::Swiftlint::OutputParser

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/swiftlint/output_parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(output) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pronto/swiftlint/output_parser.rb', line 6

def parse(output)
  begin
    violations = JSON.parse(output)
  rescue => e
    puts "pronto-swiftlint ERROR: failed to parse output. Is formatter set to json? #{e}"
    return {}
  end

  result = {}
  violations.each do |violation|
    file = violation['file']
    result[file] ||= []
    result[file] << {
      file: violation['file'],
      line: violation['line'],
      column: violation['character'],
      level: parse_severity(violation['severity']),
      message: violation['reason'],
      rule: violation['rule_id']
    }
  end
  result
end