2017-12-15 11:24:15 +00:00
|
|
|
# Copyright (c) 2014 Vlad Temian <vladtemian@gmail.com>
|
2018-07-15 09:36:36 +00:00
|
|
|
# Copyright (c) 2015-2017 Claudiu Popa <pcmanticore@gmail.com>
|
2017-12-15 11:24:15 +00:00
|
|
|
# Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
|
|
|
|
# Copyright (c) 2017 guillaume2 <guillaume.peillex@gmail.col>
|
2016-07-22 21:22:28 +00:00
|
|
|
|
2016-06-01 15:11:29 +00:00
|
|
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
|
|
|
|
|
2014-11-04 20:16:20 +00:00
|
|
|
"""JSON reporter"""
|
|
|
|
from __future__ import absolute_import, print_function
|
|
|
|
|
2019-02-05 07:48:04 +00:00
|
|
|
import html
|
2014-11-04 20:16:20 +00:00
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from pylint.interfaces import IReporter
|
|
|
|
from pylint.reporters import BaseReporter
|
|
|
|
|
|
|
|
|
|
|
|
class JSONReporter(BaseReporter):
|
2014-11-22 10:54:32 +00:00
|
|
|
"""Report messages and layouts in JSON."""
|
2014-11-04 20:16:20 +00:00
|
|
|
|
|
|
|
__implements__ = IReporter
|
2018-09-16 15:33:50 +00:00
|
|
|
name = "json"
|
|
|
|
extension = "json"
|
2014-11-04 20:16:20 +00:00
|
|
|
|
|
|
|
def __init__(self, output=sys.stdout):
|
|
|
|
BaseReporter.__init__(self, output)
|
|
|
|
self.messages = []
|
|
|
|
|
2016-07-10 13:48:46 +00:00
|
|
|
def handle_message(self, msg):
|
2014-11-04 20:16:20 +00:00
|
|
|
"""Manage message of different type and in the context of path."""
|
2018-09-16 15:33:50 +00:00
|
|
|
self.messages.append(
|
|
|
|
{
|
|
|
|
"type": msg.category,
|
|
|
|
"module": msg.module,
|
|
|
|
"obj": msg.obj,
|
|
|
|
"line": msg.line,
|
|
|
|
"column": msg.column,
|
|
|
|
"path": msg.path,
|
|
|
|
"symbol": msg.symbol,
|
2019-02-28 16:18:00 +00:00
|
|
|
"message": html.escape(msg.msg or "", quote=False),
|
2018-09-16 15:33:50 +00:00
|
|
|
"message-id": msg.msg_id,
|
|
|
|
}
|
|
|
|
)
|
2014-11-04 20:16:20 +00:00
|
|
|
|
2016-01-09 19:24:05 +00:00
|
|
|
def display_messages(self, layout):
|
2014-11-04 20:16:20 +00:00
|
|
|
"""Launch layouts display"""
|
2018-09-06 06:32:44 +00:00
|
|
|
print(json.dumps(self.messages, indent=4), file=self.out)
|
2014-11-04 20:16:20 +00:00
|
|
|
|
2018-09-16 15:33:50 +00:00
|
|
|
def display_reports(self, layout): # pylint: disable=arguments-differ
|
2016-01-09 19:24:05 +00:00
|
|
|
"""Don't do nothing in this reporter."""
|
|
|
|
|
2016-01-09 20:09:03 +00:00
|
|
|
def _display(self, layout):
|
2018-10-02 06:38:15 +00:00
|
|
|
"""Do nothing."""
|
2016-01-09 20:09:03 +00:00
|
|
|
|
2014-11-04 20:16:20 +00:00
|
|
|
|
|
|
|
def register(linter):
|
|
|
|
"""Register the reporter classes with the linter."""
|
|
|
|
linter.register_reporter(JSONReporter)
|