Skip to content

Instantly share code, notes, and snippets.

@macklinu
Last active August 29, 2015 14:26
Show Gist options
  • Save macklinu/61e90eede664260a2449 to your computer and use it in GitHub Desktop.
Save macklinu/61e90eede664260a2449 to your computer and use it in GitHub Desktop.
A Checkstyle checks counter

Checkstyle Violation Counter

A short script to count Checkstyle violation types.

Usage

$ ruby xml.rb /path/to/checkstyle-results.xml

Output

{"MethodNameCheck"=>218,
 "LineLengthCheck"=>139,
 "WhitespaceAroundCheck"=>93,
 "NewlineAtEndOfFileCheck"=>54,
 "JavadocStyleCheck"=>35,
 "OperatorWrapCheck"=>30,
 "UpperEllCheck"=>18,
 "MemberNameCheck"=>17,
 "HideUtilityClassConstructorCheck"=>16,
 "StaticVariableNameCheck"=>14,
 "ModifierOrderCheck"=>7,
 "UnusedImportsCheck"=>2,
 "ParameterNameCheck"=>1,
 "FileTabCharacterCheck"=>1,
 "WhitespaceAfterCheck"=>1}
require 'nokogiri'
require 'pp'
fail 'must supply 1 argument: checkstyle results XML file' if ARGV.length != 1
xml = Nokogiri::XML(File.open(ARGV[0]))
pp xml.xpath('//error[@source]')
.inject([]) { |a, e| a.push(e.attributes['source'].value) }
.map { |e| e.split('.')[-1].strip }
.reduce({}) { |a, e| a.update(e => a.fetch(e, 0) + 1) }
.sort_by { |_, v| -v }
.to_h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment