This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
reporter.py
72 lines (60 loc) · 2.22 KB
/
reporter.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import json
from pylint.interfaces import IReporter
from pylint.reporters import BaseReporter
class CodeClimateReporter(BaseReporter):
__implements__ = IReporter
name = 'codeclimate'
extension = 'json'
category_map = {
'convention': ['Style'],
'refactor': ['Complexity'],
'warning': ['Bug Risk'],
'error': ['Bug Risk'],
'fatal': ['Bug Risk'],
}
severity_map = {
'convention': 'info',
'refactor': 'info',
'warning': 'normal',
'error': 'critical',
'fatal': 'critical',
}
def handle_message(self, pylint_issue):
codeclimate_dict = dict()
codeclimate_dict['type'] = 'issue'
codeclimate_dict['check_name'] = pylint_issue.symbol
codeclimate_dict['categories'] = self.category_map[pylint_issue.category]
message = self._parse_message(pylint_issue.msg)
message_lines = message.splitlines()
codeclimate_dict['description'] = message_lines[0]
message_definition = self.linter.msgs_store.get_message_definitions(pylint_issue.symbol)
if message_definition:
message_definition = message_definition[0]
body = self._parse_message(message_definition.description)
for line in message_lines[1:]:
body += "\n" + line
codeclimate_dict['content'] = {'body': body}
location = dict()
location['path'] = pylint_issue.path
location['positions'] = {
'begin': {
'line': pylint_issue.line,
'column': pylint_issue.column,
},
'end': {
'line': pylint_issue.line,
'column': pylint_issue.column,
},
}
codeclimate_dict['location'] = location
codeclimate_dict['severity'] = self.severity_map[pylint_issue.category]
codeclimate_string = json.dumps(codeclimate_dict, indent=4)
self.writeln(codeclimate_string + "\0")
def _parse_message(self, message):
while ' ' in message:
message = message.replace(' ', ' ')
message = message.replace('"', '`')
message = message.replace('\\', '')
return message
def _display(self, layout):
pass