class Pronto::PerlLint

Public Class Methods

new(patches, commit = nil) click to toggle source
Calls superclass method
# File lib/pronto/perl_lint.rb, line 8
def initialize(patches, commit = nil)
  super
  @lint = "#{File.expand_path(File.dirname(__FILE__))}/../../bin/perllint"
end

Public Instance Methods

inspect(patch) click to toggle source
# File lib/pronto/perl_lint.rb, line 25
def inspect(patch)
  path = patch.new_file_full_path.to_s
  offences = run_perl_lint(path)

  offences.map do |offence|
    patch.added_lines
         .select { |line| line.new_lineno == offence['line'] }
         .map { |line| new_message(offence, line) }
  end
end
message(offence) click to toggle source
# File lib/pronto/perl_lint.rb, line 43
def message(offence)
  "#{offence['policy']}: #{offence['description']}"
end
new_message(offence, line) click to toggle source
# File lib/pronto/perl_lint.rb, line 36
def new_message(offence, line)
  path = line.patch.delta.new_file[:path]
  level = :info

  Message.new(path, line, level, message(offence), nil, self.class)
end
perl_file?(path) click to toggle source
# File lib/pronto/perl_lint.rb, line 57
def perl_file?(path)
  Linguist::FileBlob.new(path, Dir.pwd).language.name == 'Perl'
end
run() click to toggle source
# File lib/pronto/perl_lint.rb, line 13
def run
  return [] unless @patches

  @patches.select { |patch| valid_patch?(patch) }
          .map { |patch| inspect(patch) }
          .flatten.compact
end
run_perl_lint(path) click to toggle source
# File lib/pronto/perl_lint.rb, line 47
def run_perl_lint(path)
  begin
    json = `#{Shellwords.escape(@lint)} #{Shellwords.escape(path)}`
    return JSON.parse(json)
  rescue JSON::ParserError => e
    STDERR.puts e.backtrace
    return []
  end
end
valid_patch?(patch) click to toggle source
# File lib/pronto/perl_lint.rb, line 21
def valid_patch?(patch)
  patch.additions > 0 && perl_file?(patch.new_file_full_path)
end