Class: Pronto::Dogma::Runner

Inherits:
Runner
  • Object
show all
Defined in:
lib/pronto/dogma.rb

Constant Summary collapse

ELIXIR_EXTENSIONS =
%w(.ex .exs).freeze

Instance Method Summary collapse

Instance Method Details

#affected_lines(patch) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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_linesObject



47
48
49
50
51
52
# 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_pathnameObject



41
42
43
44
45
# File 'lib/pronto/dogma.rb', line 41

def dogma_output_pathname
  @dogma_output_path ||= Pathname.new(
    ENV["PRONTO_DOGMA_OUTPUT"] || "dogma.out"
  )
end

#elixir_patchesObject



35
36
37
38
39
# 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) ⇒ Object



31
32
33
# File 'lib/pronto/dogma.rb', line 31

def new_message(line, dline)
  Pronto::Message.new(dline.path, line, :warning, dline.error)
end

#runObject



8
9
10
11
12
13
# 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