class Danger::DangerInspect

Danger plugin for code inspections.

@example Parse the XML files, and report messages.

inspect.report 'path/to/inspect-result_dir'

@see shogo4405/danger-inspect @tags lint

Public Instance Methods

report(dir) click to toggle source

Report code inspections messages.

@return [void]

# File lib/inspect/plugin.rb, line 17
def report(dir)
  problems = []
  Dir.glob("#{dir}/*.xml") do |file|
    problems.push(read_xml(file)) unless file.include?('.descriptions.xml')
  end
  comment(problems.flatten)
end

Private Instance Methods

comment(problems) click to toggle source
# File lib/inspect/plugin.rb, line 37
def comment(problems)
  problems.each do |problem|
    case problem.severity.downcase
    when 'info'
      message(problem.message, file: problem.file, line: problem.line)
    else
      warn(problem.message, file: problem.file, line: problem.line)
    end
  end
end
read_xml(file) click to toggle source
# File lib/inspect/plugin.rb, line 27
def read_xml(file)
  require 'rexml/document'
  problems = []
  xml = REXML::Document.new(File.read(file))
  xml
    .get_elements('problems/problem')
    .each { |element| problems.push(Problem.generate(element)) }
  problems
end