1
|
|
|
import sys |
2
|
|
|
import re |
3
|
|
|
|
4
|
|
|
from coalib.bearlib.abstractions.Lint import Lint |
5
|
|
|
from coalib.bears.LocalBear import LocalBear |
6
|
|
|
from coalib.settings.Setting import typed_list |
7
|
|
|
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
# We omit this case in our tests for technical reasons |
11
|
|
|
if sys.version_info < (3, 3): # pragma: no cover |
12
|
|
|
raise ImportError("PyLint does not support python3 < 3.3") |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class PyLintBear(LocalBear, Lint): |
16
|
|
|
executable = 'pylint' |
17
|
|
|
arguments = ('--reports=n --persistent=n --msg-template=' |
18
|
|
|
'"{line}.{column}|{C}: {msg_id} - {msg}"') |
19
|
|
|
output_regex = re.compile(r'(?P<line>\d+)\.(?P<column>\d+)' |
20
|
|
|
r'\|(?P<severity>[WFECRI]): (?P<message>.*)') |
21
|
|
|
severity_map = { |
22
|
|
|
"F": RESULT_SEVERITY.MAJOR, |
23
|
|
|
"E": RESULT_SEVERITY.MAJOR, |
24
|
|
|
"W": RESULT_SEVERITY.NORMAL, |
25
|
|
|
"C": RESULT_SEVERITY.INFO, |
26
|
|
|
"R": RESULT_SEVERITY.INFO, |
27
|
|
|
"I": RESULT_SEVERITY.INFO} |
28
|
|
|
|
29
|
|
|
def run(self, |
30
|
|
|
filename, |
31
|
|
|
file, |
32
|
|
|
pylint_disable: typed_list(str)=("fixme"), |
33
|
|
|
pylint_enable: typed_list(str)=None, |
34
|
|
|
pylint_cli_options: str=""): |
35
|
|
|
''' |
36
|
|
|
Checks the code with pylint. This will run pylint over each file |
37
|
|
|
separately. |
38
|
|
|
|
39
|
|
|
:param pylint_disable: Disable the message, report, category or |
40
|
|
|
checker with the given id(s). |
41
|
|
|
:param pylint_enable: Enable the message, report, category or |
42
|
|
|
checker with the given id(s). |
43
|
|
|
:param pylint_cli_options: Any command line options you wish to be |
44
|
|
|
passed to pylint. |
45
|
|
|
''' |
46
|
|
|
if pylint_disable: |
47
|
|
|
self.arguments += " --disable=" + ",".join(pylint_disable) |
48
|
|
|
if pylint_enable: |
49
|
|
|
self.arguments += " --enable=" + ",".join(pylint_enable) |
50
|
|
|
if pylint_cli_options: |
51
|
|
|
self.arguments += " " + pylint_cli_options |
52
|
|
|
|
53
|
|
|
return self.lint(filename) |
54
|
|
|
|