third_party.pylibs.pylint.src/pylint/reporters/json.py

61 lines
1.8 KiB
Python
Raw Normal View History

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>
# 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 = []
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,
"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
def display_messages(self, layout):
2014-11-04 20:16:20 +00:00
"""Launch layouts display"""
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
"""Don't do nothing in this reporter."""
def _display(self, layout):
2018-10-02 06:38:15 +00:00
"""Do nothing."""
2014-11-04 20:16:20 +00:00
def register(linter):
"""Register the reporter classes with the linter."""
linter.register_reporter(JSONReporter)