Sha256: 3de6660edc5a54ce43a3c359472e1184b2403f0c9a53e17a4e367a205d516bac
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
require 'json' require 'rexml/document' module SwiftlintTranslateCheckstyleFormat module Translate def parse(str) JSON.load(str) end def trans(json) doc = REXML::Document.new doc << REXML::XMLDecl.new('1.0', 'UTF-8') checkstyle = doc.add_element('checkstyle') if json.empty? SwiftlintTranslateCheckstyleFormat::Translate.add_dummy(checkstyle) return doc end json.each do |result| file = checkstyle.add_element('file', 'name' => result['file'] ) file.add_element('error', 'line' => result['line'], 'severity' => 'error', 'message' => SwiftlintTranslateCheckstyleFormat::Translate.create_message(result) ) end doc end def self.add_dummy(checkstyle) checkstyle.add_element('file', 'name' => '' ) checkstyle end def self.create_message(result) "[#{result['severity']}][#{result['rule_id']}] #{result['type']}\n#{result['reason']}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
swiftlint_translate_checkstyle_format-0.1.1 | lib/swiftlint_translate_checkstyle_format/translate.rb |