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