forked from jjarboe/analysis-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pylint_import.py
55 lines (45 loc) · 1.94 KB
/
pylint_import.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from coverity_import import CoverityIssueCollector, get_opts
import re
import os.path
import sys
class PyLintCollector(CoverityIssueCollector):
'''
A simple collector for PyLint reports.
The PyLint analysis should be run with the following options:
-r n
--msg-template="{path}:{line}: ({msg_id}) {symbol}: {obj}: {msg}"
In addition, we recommend the following options:
-d C0103,C0301,C0330,C0111,W0401,W0614
'''
_report_re = re.compile(r'^(?P<file>.+?):(?P<line>\d+):\s*\[(?P<subcategory>.+?)\((?P<tag>.+?)\), (?P<function>.*)\] (?P<description>.+)$', re.M)
def process(self, f):
'''
This method assumes that reports are isolated to a single line.
If your tool reports issues on multiple lines, or for some other
reason the report lines may not be reordered, you'll need to
override this method to handle things appropriately.
'''
for l in f:
l = l.strip()
if not l: continue
# Pylint marks the start of a module with a line like **** <module>
if l.startswith('*****'): continue
m = self._report_re.match(l)
if m:
f = m.groupdict()
msg = self.create_issue(checker = 'PyLint.'+f['tag'],
tag = f['tag'],
description = f['description'],
function = f['function'],
subcategory = f['subcategory']
)
msg.add_location(f['line'], f['file'], f['description'])
self.add_issue(msg)
else:
# Pylint inserts code snippets for some issues; skip those lines
pass
#print 'Unrecognized input format:', l
#sys.exit(-1)
if __name__ == '__main__':
opts = get_opts('pylint_import.py', sys.argv)
print PyLintCollector(**opts).run(sys.argv[-1])