Class: Overcommit::Hook::PreCommit::PythonFlake8

Inherits:
Base
  • Object
show all
Defined in:
lib/overcommit/hook/pre_commit/python_flake8.rb

Overview

Runs ‘flake8` against any modified Python files.

Constant Summary collapse

MESSAGE_REGEX =
/^(?<file>(?:\w:)?.+):(?<line>\d+):\d+:\s(?<type>\w\d+)/
MESSAGE_TYPE_CATEGORIZER =

Classify ‘Exxx’ and ‘Fxxx’ message codes as errors, everything else as warnings.

http://flake8.readthedocs.org/en/latest/warnings.html
lambda do |type|
  'EF'.include?(type[0]) ? :error : :warning
end

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #command, #description, #enabled?, #execute, #execute_in_background, #flags, #in_path?, #included_files, #initialize, #name, #parallelize?, #processors, #quiet?, #required?, #required_executable, #required_libraries, #run?, #run_and_transform, #skip?

Constructor Details

This class inherits a constructor from Overcommit::Hook::Base

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/overcommit/hook/pre_commit/python_flake8.rb', line 17

def run
  result = execute(command, args: applicable_files)
  return :pass if result.success?

  output = result.stdout.chomp

  # example message:
  #   path/to/file.py:2:13: F812 list comprehension redefines name from line 1
  extract_messages(
    output.split("\n").grep(MESSAGE_REGEX),
    MESSAGE_REGEX,
    MESSAGE_TYPE_CATEGORIZER
  )
end