class Pronto::ClippyRunner

Attributes

patches[R]

Public Instance Methods

offences() click to toggle source
# File lib/pronto/clippy_runner.rb, line 18
def offences
  @offences ||= Clippy::Wrapper.new.lint
end
run() click to toggle source
# File lib/pronto/clippy_runner.rb, line 8
def run
  return [] unless @patches


  patches
    .reject { |patch| patch.additions.zero? }
    .select { |patch| rust_file?(patch.new_file_full_path.to_s) }
    .map { |patch| inspect(patch) }
end

Private Instance Methods

contains?(patch, span) click to toggle source
# File lib/pronto/clippy_runner.rb, line 34
def contains?(patch, span)
  line_start = span['line_start'].to_i
  line_end = span['line_end'].to_i

  patch.added_lines.find do |entry|
    (line_start..line_end).cover?(entry.new_lineno)
  end
end
inspect(patch) click to toggle source
# File lib/pronto/clippy_runner.rb, line 24
def inspect(patch)
  offences
    .fetch(patch.new_file_full_path.to_s, [])
    .inject([]) do |arr, offence|
    line = contains?(patch, offence['spans'].first)
    arr << new_message(offence, line) if line
    arr
  end
end
new_message(offence, line) click to toggle source
# File lib/pronto/clippy_runner.rb, line 43
def new_message(offence, line)
  path = line.patch.delta.new_file[:path]
  Message.new(path,
              line,
              offence['level'].to_sym,
              offence['message'],
              nil,
              self.class)
end
rust_file?(path) click to toggle source
# File lib/pronto/clippy_runner.rb, line 53
def rust_file?(path)
  %w(.rs).include?(File.extname(path))
end