class Pronto::Dogma::Runner

Constants

ELIXIR_EXTENSIONS

Public Instance Methods

affected_lines(patch) click to toggle source
# File lib/pronto/dogma.rb, line 15
def affected_lines(patch)
  candidate_lines = patch.lines.select { |line| line.addition? }
  candidate_lines.reduce([]) do |accum, line|
    affected_line = dogma_lines.find do |dline|
      patch.repo.path.join(dline.path) == patch.new_file_full_path &&
        dline.lineno == line.new_lineno
    end

    if affected_line
      accum << new_message(line, affected_line)
    else
      accum
    end
  end
end
dogma_lines() click to toggle source
# File lib/pronto/dogma.rb, line 47
def dogma_lines
  @dogma_lines ||= matching_lines(
    dogma_output_pathname,
    /(?<path>.+\.[a-z]{2,3}):(?<lineno>[0-9]+):[0-9]+: [A-Z]: (?<error_msg>.+)/
  )
end
dogma_output_pathname() click to toggle source
# File lib/pronto/dogma.rb, line 41
def dogma_output_pathname
  @dogma_output_path ||= Pathname.new(
    ENV["PRONTO_DOGMA_OUTPUT"] || "dogma.out"
  )
end
elixir_patches() click to toggle source
# File lib/pronto/dogma.rb, line 35
def elixir_patches
  @patches.select do |patch|
    ELIXIR_EXTENSIONS.member?(File.extname(patch.new_file_full_path))
  end
end
new_message(line, dline) click to toggle source
# File lib/pronto/dogma.rb, line 31
def new_message(line, dline)
  Pronto::Message.new(dline.path, line, :warning, dline.error)
end
run() click to toggle source
# File lib/pronto/dogma.rb, line 8
def run
  return [] unless dogma_output_pathname.exist?
  elixir_patches
    .select { |patch| patch.delta.status != :deleted }
    .flat_map { |patch| affected_lines(patch) }
end

Private Instance Methods

matching_lines(pathname, line_regex) click to toggle source
# File lib/pronto/dogma.rb, line 56
def matching_lines(pathname, line_regex)
  pathname.readlines.reduce([]) do |accum, line|
    if match = line.match(line_regex)
      accum << OpenStruct.new(
        path: match[:path],
        lineno: match[:lineno].to_i,
        error: match[:error_msg]
      )
    else
      accum
    end
  end
end