class Overcommit::Hook::PreCommit::Pyflakes

Runs `pyflakes` against any modified Python files.

@see pypi.python.org/pypi/pyflakes

Constants

MESSAGE_REGEX

Public Instance Methods

run() click to toggle source
# File lib/overcommit/hook/pre_commit/pyflakes.rb, line 10
def run
  result = execute(command, args: applicable_files)
  return :pass if result.success?

  errors = get_messages(result.stderr, :error)
  warnings = get_messages(result.stdout, :warning)

  errors + warnings
end

Private Instance Methods

get_messages(output, type) click to toggle source
# File lib/overcommit/hook/pre_commit/pyflakes.rb, line 22
def get_messages(output, type)
  # example message:
  #   path/to/file.py:57: local variable 'x' is assigned to but never used
  extract_messages(
    output.split("\n").grep(MESSAGE_REGEX),
    MESSAGE_REGEX,
    proc { type }
  )
end