forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyflakes.rb
32 lines (26 loc) · 799 Bytes
/
pyflakes.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true
module Overcommit::Hook::PreCommit
# Runs `pyflakes` against any modified Python files.
#
# @see https://pypi.python.org/pypi/pyflakes
class Pyflakes < Base
MESSAGE_REGEX = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+):/
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
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
end
end