Skip to content

Instantly share code, notes, and snippets.

@threez
Last active April 18, 2016 09:24
Show Gist options
  • Save threez/504ac4417dfe6cc5e7de753c616395cf to your computer and use it in GitHub Desktop.
Save threez/504ac4417dfe6cc5e7de753c616395cf to your computer and use it in GitHub Desktop.
gometalinter JSON top checkstyle converter for jenkins

Usage

gometalinter --deadline=5s ./... --json | ./goml2checkstyle.rb > checkstyle.xml

If the output doesn't show up, the prefix path might not be detected correctly. Pass the path in manually then:

gometalinter --deadline=5s ./... --json | ./goml2checkstyle.rb /absolute/path/to/the/files > checkstyle.xml
#!/usr/bin/env ruby
require "json"
require "rexml/document"
require "rexml/element"
require "cgi"
prefix = ARGV.shift || Dir.pwd
data = JSON.load(STDIN.read)
files={}
Dir.glob("./**/*.go").each do |path|
files[path.gsub("./", "")] = []
end
data.each do |record|
files[record['path']] << record
end
doc = REXML::Document.new('<checkstyle version="5.0"></checkstyle>')
root = doc.root
files.each do |path, records|
file = REXML::Element.new("file")
file.add_attribute 'name', File.join(prefix, path)
records.each do |record|
elem = REXML::Element.new("error")
elem.add_attribute 'column', record["col"]
elem.add_attribute 'line', record["line"]
elem.add_attribute 'severity', record["severity"]
elem.add_attribute 'message', CGI.escapeHTML(record["message"])
elem.add_attribute 'source', record["linter"]
file << elem
end
root << file
end
puts '<?xml version="1.0" encoding="UTF-8"?>'
doc.write(STDOUT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment