Class: Reek::CheckstyleFormatter
- Inherits:
-
Object
- Object
- Reek::CheckstyleFormatter
- Defined in:
- lib/reek-checkstyle-formatter/version.rb,
lib/reek-checkstyle-formatter.rb
Constant Summary collapse
- VERSION =
"0.0.2"
- REXML_PRETTY_PRINT_INDENT =
0
Class Attribute Summary collapse
-
.rake_task_options ⇒ Object
Returns the value of attribute rake_task_options.
Instance Attribute Summary collapse
-
#glob_pattern ⇒ Object
Returns the value of attribute glob_pattern.
-
#output ⇒ Object
Returns the value of attribute output.
-
#smell_doc_url ⇒ Object
Returns the value of attribute smell_doc_url.
-
#smell_severities ⇒ Object
Returns the value of attribute smell_severities.
Instance Method Summary collapse
- #add_file(checkstyle_node, examined_file) ⇒ Object
- #add_smell(file_node, smell, line) ⇒ Object
-
#initialize(opts = {}) ⇒ CheckstyleFormatter
constructor
A new instance of CheckstyleFormatter.
- #run ⇒ Object
- #smell_anchor(smell) ⇒ Object
- #smell_message(smell) ⇒ Object
- #smell_severity(smell) ⇒ Object
- #smell_url(smell) ⇒ Object
- #to_checkstyle(examined_files) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ CheckstyleFormatter
Returns a new instance of CheckstyleFormatter.
23 24 25 26 27 28 |
# File 'lib/reek-checkstyle-formatter.rb', line 23 def initialize(opts = {}) @glob_pattern = opts[:glob_pattern] @output = opts[:output] @smell_doc_url = opts[:smell_doc_url] @smell_severities = opts[:smell_severities] || {} end |
Class Attribute Details
.rake_task_options ⇒ Object
Returns the value of attribute rake_task_options.
10 11 12 |
# File 'lib/reek-checkstyle-formatter.rb', line 10 def @rake_task_options end |
Instance Attribute Details
#glob_pattern ⇒ Object
Returns the value of attribute glob_pattern.
16 17 18 |
# File 'lib/reek-checkstyle-formatter.rb', line 16 def glob_pattern @glob_pattern end |
#output ⇒ Object
Returns the value of attribute output.
16 17 18 |
# File 'lib/reek-checkstyle-formatter.rb', line 16 def output @output end |
#smell_doc_url ⇒ Object
Returns the value of attribute smell_doc_url.
16 17 18 |
# File 'lib/reek-checkstyle-formatter.rb', line 16 def smell_doc_url @smell_doc_url end |
#smell_severities ⇒ Object
Returns the value of attribute smell_severities.
16 17 18 |
# File 'lib/reek-checkstyle-formatter.rb', line 16 def smell_severities @smell_severities end |
Instance Method Details
#add_file(checkstyle_node, examined_file) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/reek-checkstyle-formatter.rb', line 54 def add_file(checkstyle_node, examined_file) if examined_file.smells.length > 0 REXML::Element.new('file', checkstyle_node).tap do |file_node| file_node.attributes['name'] = File.join(examined_file.description) examined_file.smells.each do |smell| if smell.status['is_active'] [*smell.location['lines']].each do |line| add_smell(file_node, smell, line) end end end end end end |
#add_smell(file_node, smell, line) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/reek-checkstyle-formatter.rb', line 69 def add_smell(file_node, smell, line) REXML::Element.new('error', file_node).tap do |error| error.attributes['line'] = line error.attributes['column'] = 0 error.attributes['severity'] = smell_severity(smell) error.attributes['message'] = (smell) #error.attributes['source'] = File.join(@project_dir, smell.source) end end |
#run ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/reek-checkstyle-formatter.rb', line 30 def run puts "Generating Reek Checkstyle XML #{self.inspect}" files = Dir.glob(@glob_pattern) sources = Reek::Source::SourceLocator.new(files).all_sources examined_files = sources.map {|src| Reek::Examiner.new(src, []) } document = to_checkstyle(examined_files) Pathname.new(@output).dirname.mkpath File.open(@output, 'w+') do |file| document.write(file, REXML_PRETTY_PRINT_INDENT) end puts "Reek Checkstyle XML written to #{self.output}" end |
#smell_anchor(smell) ⇒ Object
83 84 85 86 |
# File 'lib/reek-checkstyle-formatter.rb', line 83 def smell_anchor(smell) url = smell_url(smell) "<a href='#{url}'>#{smell.smell['subclass']}</a>" end |
#smell_message(smell) ⇒ Object
79 80 81 |
# File 'lib/reek-checkstyle-formatter.rb', line 79 def (smell) "<em>#{smell_anchor(smell)}</em> - #{smell.}" end |
#smell_severity(smell) ⇒ Object
93 94 95 |
# File 'lib/reek-checkstyle-formatter.rb', line 93 def smell_severity(smell) @smell_severities[smell.smell['subclass']] || 'warning' end |
#smell_url(smell) ⇒ Object
88 89 90 91 |
# File 'lib/reek-checkstyle-formatter.rb', line 88 def smell_url(smell) smell_page_name = (smell.smell['subclass']).scan(/[A-Z][^A-Z]*/).join('-') [@smell_doc_url, smell_page_name].join("/") end |
#to_checkstyle(examined_files) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/reek-checkstyle-formatter.rb', line 43 def to_checkstyle(examined_files) REXML::Document.new.tap do |document_node| document_node << REXML::XMLDecl.new REXML::Element.new('checkstyle', document_node).tap do |checkstyle_node| examined_files.each do |examined_file| add_file(checkstyle_node, examined_file) end end end end |