Show More
@@ -7,56 +7,33 from __future__ import absolute_import, | |||||
7 | import re |
|
7 | import re | |
8 | import sys |
|
8 | import sys | |
9 |
|
9 | |||
10 | def makekey(typeandline): |
|
|||
11 | """ |
|
|||
12 | for sorting lines by: msgtype, path/to/file, lineno, message |
|
|||
13 |
|
||||
14 | typeandline is a sequence of a message type and the entire message line |
|
|||
15 | the message line format is path/to/file:line: message |
|
|||
16 |
|
||||
17 | >>> makekey((3, 'example.py:36: any message')) |
|
|||
18 | (3, 'example.py', 36, ' any message') |
|
|||
19 | >>> makekey((7, 'path/to/file.py:68: dummy message')) |
|
|||
20 | (7, 'path/to/file.py', 68, ' dummy message') |
|
|||
21 | >>> makekey((2, 'fn:88: m')) > makekey((2, 'fn:9: m')) |
|
|||
22 | True |
|
|||
23 | """ |
|
|||
24 |
|
||||
25 | msgtype, line = typeandline |
|
|||
26 | fname, line, message = line.split(":", 2) |
|
|||
27 | # line as int for ordering 9 before 88 |
|
|||
28 | return msgtype, fname, int(line), message |
|
|||
29 |
|
||||
30 |
|
||||
31 | lines = [] |
|
10 | lines = [] | |
32 | for line in sys.stdin: |
|
11 | for line in sys.stdin: | |
33 | # We whitelist tests (see more messages in pyflakes.messages) |
|
12 | # We blacklist tests that are too noisy for us | |
34 | pats = [ |
|
13 | pats = [ | |
35 | (r"imported but unused", None), |
|
14 | r"undefined name '(WindowsError|memoryview)'", | |
36 | (r"local variable '.*' is assigned to but never used", None), |
|
15 | r"redefinition of unused '[^']+' from line", | |
37 | (r"unable to detect undefined names", None), |
|
16 | ] | |
38 | (r"undefined name '.*'", |
|
|||
39 | r"undefined name '(WindowsError|memoryview)'"), |
|
|||
40 | ("list comprehension", None), |
|
|||
41 | ] |
|
|||
42 |
|
17 | |||
43 | for msgtype, (pat, excl) in enumerate(pats): |
|
18 | keep = True | |
44 | if re.search(pat, line) and (not excl or not re.search(excl, line)): |
|
19 | for pat in pats: | |
|
20 | if re.search(pat, line): | |||
|
21 | keep = False | |||
45 | break # pattern matches |
|
22 | break # pattern matches | |
46 |
e |
|
23 | if keep: | |
47 | continue # no pattern matched, next line |
|
24 | fn = line.split(':', 1)[0] | |
48 | fn = line.split(':', 1)[0] |
|
25 | f = open(fn) | |
49 | f = open(fn) |
|
26 | data = f.read() | |
50 |
|
|
27 | f.close() | |
51 | f.close() |
|
28 | if 'no-' 'check-code' in data: | |
52 | if 'no-' 'check-code' in data: |
|
29 | continue | |
53 | continue |
|
30 | lines.append(line) | |
54 | lines.append((msgtype, line)) |
|
|||
55 |
|
31 | |||
56 | for msgtype, line in sorted(lines, key=makekey): |
|
32 | for line in lines: | |
57 | sys.stdout.write(line) |
|
33 | sys.stdout.write(line) | |
58 | print() |
|
34 | print() | |
59 |
|
35 | |||
60 | # self test of "undefined name" detection for other than 'memoryview' |
|
36 | # self test of "undefined name" detection for other than 'memoryview' | |
61 | if False: |
|
37 | if False: | |
|
38 | print(memoryview) | |||
62 | print(undefinedname) |
|
39 | print(undefinedname) |
@@ -10,6 +10,6 run pyflakes on all tracked files ending | |||||
10 | > -X mercurial/pycompat.py \ |
|
10 | > -X mercurial/pycompat.py \ | |
11 | > 2>/dev/null \ |
|
11 | > 2>/dev/null \ | |
12 | > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py" |
|
12 | > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py" | |
13 |
tests/filterpyflakes.py: |
|
13 | tests/filterpyflakes.py:39: undefined name 'undefinedname' | |
14 |
|
14 | |||
15 |
|
15 |
General Comments 0
You need to be logged in to leave comments.
Login now