Class: Reek::Report::XMLReport

Inherits:
BaseReport show all
Defined in:
lib/reek/report/xml_report.rb

Overview

Generates a list of smells in XML format

Constant Summary

Constants inherited from BaseReport

BaseReport::NO_WARNINGS_COLOR, BaseReport::WARNINGS_COLOR

Instance Attribute Summary

Attributes inherited from BaseReport

#examiners, #heading_formatter, #progress_formatter, #sort_by_issue_count, #warning_formatter

Instance Method Summary collapse

Methods inherited from BaseReport

#add_examiner, #initialize, #smells, #smells?

Constructor Details

This class inherits a constructor from Reek::Report::BaseReport

Instance Method Details

#checkstyleObject (private)



29
30
31
32
33
34
35
# File 'lib/reek/report/xml_report.rb', line 29

def checkstyle
  REXML::Element.new('checkstyle').tap do |checkstyle|
    smells.group_by(&:source).each do |source, source_smells|
      checkstyle << file(source, source_smells)
    end
  end
end

#documentObject (private)



23
24
25
26
27
# File 'lib/reek/report/xml_report.rb', line 23

def document
  REXML::Document.new.tap do |document|
    document << REXML::XMLDecl.new << checkstyle
  end
end

#error(smell, line) ⇒ Object (private)



51
52
53
54
55
56
57
58
59
# File 'lib/reek/report/xml_report.rb', line 51

def error(smell, line)
  REXML::Element.new('error').tap do |error|
    error.add_attributes 'column' => 0,
                         'line' => line,
                         'message' => smell.message,
                         'severity' => 'warning',
                         'source' => smell.smell_type
  end
end

#file(name, smells) ⇒ Object (private)



39
40
41
42
43
44
45
46
47
48
# File 'lib/reek/report/xml_report.rb', line 39

def file(name, smells)
  REXML::Element.new('file').tap do |file|
    file.add_attribute 'name', File.realpath(name)
    smells.each do |smell|
      smell.lines.each do |line|
        file << error(smell, line)
      end
    end
  end
end

#showObject



16
17
18
19
# File 'lib/reek/report/xml_report.rb', line 16

def show
  document.write output: $stdout, indent: 2
  $stdout.puts
end