-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvcs-diff-lint-csdiff-pylint
executable file
·47 lines (35 loc) · 1.26 KB
/
vcs-diff-lint-csdiff-pylint
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
#! /usr/bin/python3
"""
The csdiff tool doesn't support the Pylint's JSON output yet. So this just a
trivial wrapper which reads Pylint's report and transforms it to JSON which is
supported by csdiff.
The script accepts the same parameters as pylint itself.
"""
import sys
import json
from subprocess import run, PIPE
PYLINT = ["pylint", "-rn", "--score=no", "--output-format=json"]
def _main():
pylint_command = PYLINT + sys.argv[1:]
# pylint: disable=subprocess-run-check
pylint_result = run(pylint_command, stdout=PIPE, stderr=PIPE)
data = json.loads(pylint_result.stdout)
for defect in data:
message = defect["obj"] + ": " if defect["obj"] else ""
message += defect["message"]
column = defect["column"] or ""
colsep = ":" if column else ""
print("Error: PYLINT_WARNING:")
print("{file}:{line}{colsep}{column}: {event}: {msg}".format(
file=defect["path"],
line=defect["line"],
colsep=colsep,
column=column,
event="{}[{}]".format(defect["message-id"],
defect["symbol"]),
msg=message,
))
print()
return pylint_result.returncode
if __name__ == "__main__":
sys.exit(_main())