class Pronto::Formatter::CheckstyleFormatter

Public Class Methods

name() click to toggle source
# File lib/pronto/formatter/checkstyle_formatter.rb, line 6
def self.name
  'checkstyle'
end
new() click to toggle source
# File lib/pronto/formatter/checkstyle_formatter.rb, line 10
def initialize
  @output = ''
end

Public Instance Methods

format(messages, _repo, _patches) click to toggle source
# File lib/pronto/formatter/checkstyle_formatter.rb, line 14
def format(messages, _repo, _patches)
  open_xml
  process_messages(messages)
  close_xml

  @output
end

Private Instance Methods

add_file_messages(path_messages, file) click to toggle source
# File lib/pronto/formatter/checkstyle_formatter.rb, line 40
def add_file_messages(path_messages, file)
  path_messages.each do |message|
    REXML::Element.new('error', file).tap do |e|
      e.attributes['line'] = message.line.new_lineno if message.line
      e.attributes['severity'] = to_checkstyle_severity(message.level)
      e.attributes['message'] = message.msg
      e.attributes['source'] = 'com.puppycrawl.tools.checkstyle.pronto'
    end
  end
end
close_xml() click to toggle source
# File lib/pronto/formatter/checkstyle_formatter.rb, line 51
def close_xml
  @document.write(@output, 2)
end
open_xml() click to toggle source
# File lib/pronto/formatter/checkstyle_formatter.rb, line 24
def open_xml
  @document = REXML::Document.new.tap do |d|
    d << REXML::XMLDecl.new
  end
  @checkstyle = REXML::Element.new('checkstyle', @document)
end
process_messages(messages) click to toggle source
# File lib/pronto/formatter/checkstyle_formatter.rb, line 31
def process_messages(messages)
  messages.group_by(&:path).map do |path, path_messages|
    REXML::Element.new('file', @checkstyle).tap do |file|
      file.attributes['name'] = path
      add_file_messages(path_messages, file)
    end
  end
end
to_checkstyle_severity(pronto_level) click to toggle source
# File lib/pronto/formatter/checkstyle_formatter.rb, line 55
def to_checkstyle_severity(pronto_level)
  case pronto_level
  when :error, :fatal then 'error'
  else pronto_level.to_s
  end
end