Sha256: 3af88aa19fabfa03b683cc35de63f7cbfa352f061521ae0eff2b2d4e04e7a9f3

Contents?: true

Size: 982 Bytes

Versions: 2

Compression:

Stored size: 982 Bytes

Contents

require 'json'

module Pronto
  module Swiftlint
    class OutputParser
      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

      private

      def parse_severity(severity)
        if severity == 'Warning'
          :warning
        elsif severity == 'Error'
          :error
        else
          :info
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pronto-swiftlint-0.2.0 lib/pronto/swiftlint/output_parser.rb
pronto-swiftlint-0.1.1 lib/pronto/swiftlint/output_parser.rb