Finding PMD rules with multiple examples

11 Jul 2007

I was working on some stuff before releasing PMD 4.0rc2 tonight and was trying to find any rulesets which had rules with more than one example. A Ruby one-liner to the rescue!

$ ruby -rrexml/document -e 
  'include REXML ; 
  Dir.glob("*.xml").each {|f| r = Document.new(File.read(f)).elements
  ["//ruleset/rule[count(example)>1]"] ; 
  puts f if r }'
j2ee.xml
basic.xml

XPath and Ruby are a pretty sweet combination!