mirror of
https://fuchsia.googlesource.com/third_party/github.com/pylint-dev/pylint
synced 2024-09-22 00:24:37 +00:00
Basic HTML parsing of message format implemented
This commit is contained in:
parent
eff371aabf
commit
5d3217a424
|
@ -16,11 +16,20 @@
|
|||
import sys
|
||||
from cgi import escape
|
||||
|
||||
import string #To parse formatter
|
||||
|
||||
from logilab.common.ureports import HTMLWriter, Section, Table
|
||||
|
||||
from pylint.interfaces import IReporter
|
||||
from pylint.reporters import BaseReporter, Message
|
||||
|
||||
#self.linter.config.msg_template or self.line_format
|
||||
#line_format = '{C}:{line:3d},{column:2d}: {msg} ({symbol})'
|
||||
#Default
|
||||
# self.msgs += (msg.category, msg.module, msg.obj,
|
||||
# str(msg.line), str(msg.column), escape(msg.msg))
|
||||
#Header
|
||||
# msgs = ['type', 'module', 'object', 'line', 'col_offset', 'message']
|
||||
|
||||
class HTMLReporter(BaseReporter):
|
||||
"""report messages and layouts in HTML"""
|
||||
|
@ -32,18 +41,42 @@ class HTMLReporter(BaseReporter):
|
|||
def __init__(self, output=sys.stdout):
|
||||
BaseReporter.__init__(self, output)
|
||||
self.msgs = []
|
||||
#Add placeholders for title and parsed messages
|
||||
self.header = None
|
||||
self.msgargs = []
|
||||
|
||||
def _parse_template(self):
|
||||
"""Helper function to parse the message template"""
|
||||
self.header = []
|
||||
if self.linter.config.msg_template:
|
||||
msg_template = self.linter.config.msg_template
|
||||
else:
|
||||
msg_template = '{category}{module}{obj}{line}{column}{msg}'
|
||||
|
||||
#Parse the message template
|
||||
str_formatter = string.Formatter()
|
||||
parsed_str = str_formatter.parse(msg_template)
|
||||
|
||||
for item in parsed_str:
|
||||
if item[1]:
|
||||
self.header.append(item[1])
|
||||
self.msgargs.append(item[1])
|
||||
|
||||
def add_message(self, msg_id, location, msg):
|
||||
"""manage message of different type and in the context of path"""
|
||||
msg = Message(self, msg_id, location, msg)
|
||||
#self.msgs += (msg.category, msg.module, msg.obj,
|
||||
# str(msg.line), str(msg.column), escape(msg.msg))
|
||||
if self.linter.config.html_ids:
|
||||
self.msgs += (msg.category, msg.msg_id, msg.module, msg.obj,
|
||||
str(msg.line), str(msg.column), escape(msg.msg))
|
||||
else:
|
||||
self.msgs += (msg.category, msg.module, msg.obj,
|
||||
str(msg.line), str(msg.column), escape(msg.msg))
|
||||
|
||||
#It would be better to do this in init, but currently we do not
|
||||
#have access to the linter (as it is setup in lint.set_reporter()
|
||||
#Therfore we try to parse just the once.
|
||||
if self.header is None:
|
||||
self._parse_template()
|
||||
|
||||
#We want to add the lines given by the template
|
||||
thismsg = [str(msg.__dict__.get(x, "None")) for x in self.msgargs]
|
||||
self.msgs += thismsg
|
||||
|
||||
def set_output(self, output=None):
|
||||
"""set output stream
|
||||
|
@ -60,14 +93,11 @@ class HTMLReporter(BaseReporter):
|
|||
(in add_message, message is not displayed, just collected so it
|
||||
can be displayed in an html table)
|
||||
"""
|
||||
|
||||
if self.msgs:
|
||||
# add stored messages to the layout
|
||||
if self.linter.config.html_ids:
|
||||
msgs = ['type', 'id', 'module', 'object', 'line', 'col_offset', 'message']
|
||||
cols = 7
|
||||
else:
|
||||
msgs = ['type', 'module', 'object', 'line', 'col_offset', 'message']
|
||||
cols = 6
|
||||
msgs = self.header
|
||||
cols = len(self.header)
|
||||
msgs += self.msgs
|
||||
sect = Section('Messages')
|
||||
layout.append(sect)
|
||||
|
|
Loading…
Reference in New Issue
Block a user