class Pronto::CredoRunner

Public Class Methods

new(_, _) click to toggle source
Calls superclass method
# File lib/pronto/credo_runner.rb, line 6
def initialize(_, _)
  super
end

Public Instance Methods

run() click to toggle source
# File lib/pronto/credo_runner.rb, line 10
def run
  return [] unless @patches

  compile if ENV["PRONTO_CREDO_COMPILE"] == "1"

  @patches.select { |p| p.additions > 0 }
    .select { |p| elixir_file?(p.new_file_full_path) }
    .map { |p| inspect(p) }
    .flatten
    .compact
end

Private Instance Methods

compile() click to toggle source
# File lib/pronto/credo_runner.rb, line 24
def compile
  _, _, status = Open3.capture3("mix deps.get && mix compile --force")
  raise "failed to compile" unless status.success?
end
elixir_file?(path) click to toggle source
# File lib/pronto/credo_runner.rb, line 48
def elixir_file?(path)
  %w(.ex .exs).include?(File.extname(path))
end
inspect(patch) click to toggle source
# File lib/pronto/credo_runner.rb, line 29
def inspect(patch)
  offences = Credo::Wrapper.new(patch).lint
  messages = []

  offences.each do |offence|
    messages += patch
      .added_lines
      .select { |line| line.new_lineno == offence[:line] }
      .map { |line| new_message(offence, line) }
  end

  messages.compact
end
new_message(offence, line) click to toggle source
# File lib/pronto/credo_runner.rb, line 43
def new_message(offence, line)
  path = line.patch.delta.new_file[:path]
  Message.new(path, line, offence[:level], offence[:message])
end