Class: Pronto::JavaCheckstyle::Parsing

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/ProntoJavaCheckstyle/Parsing.rb

Constant Summary collapse

TYPE_WARNINGS =
{
  "Warning" => :warning,
  "Info"  => :info,
  "Error" => :error
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Parsing

Returns a new instance of Parsing.



15
16
17
# File 'lib/pronto/ProntoJavaCheckstyle/Parsing.rb', line 15

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/pronto/ProntoJavaCheckstyle/Parsing.rb', line 7

def path
  @path
end

Instance Method Details

#parseObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pronto/ProntoJavaCheckstyle/Parsing.rb', line 19

def parse
  lint_result = File.open(@path) { |f| Nokogiri::XML(f) }
  lint_result.xpath("//issue").flat_map do |issue|
    issue.xpath(".//location").map do |location|
      {
        path: location.attribute("file").try(:value),
        line: location.attribute("line").try(:value).to_i,
        level: TYPE_WARNINGS[issue.attribute("severity").value],
        message: create_message(issue)
      }
    end
  end
rescue => e
  raise "Error while parsing file: #{@path}\n#{e.message}"
end