class CheckstyleReports::Entity::FoundFile

Attributes

errors[R]

Errors which were detected in this file

@return [Array<FoundError>]

path[R]

A absolute path to this file

@return [String]

relative_path[R]

A relative path to this file

@return [String]

Public Class Methods

new(node, prefix:) click to toggle source
# File lib/checkstyle_reports/entity/found_file.rb, line 20
def initialize(node, prefix:)
  raise "Wrong node was passed. expected file but #{node.name}" if node.name != "file"

  if prefix.end_with?(file_separator)
    @prefix = prefix
  else
    @prefix = prefix + file_separator
  end

  name = node.attributes["name"]

  if Pathname.new(name).absolute?
    raise "Bad prefix was found for #{name}. #{@prefix} was a prefix." unless name.start_with?(@prefix)

    # Use delete_prefix when min support version becomes ruby 2.5
    @relative_path = name[@prefix.length, name.length - @prefix.length]
  else
    @relative_path = name
  end

  @path = @prefix + @relative_path

  @path = node.attributes["name"]
  @errors = []

  node.elements.each("error") { |n| @errors << FoundError.new(n) }
end

Private Instance Methods

file_separator() click to toggle source
# File lib/checkstyle_reports/entity/found_file.rb, line 50
def file_separator
  File::ALT_SEPARATOR || File::SEPARATOR
end