diff options
author | Torsten Marek <shlomme@gmail.com> | 2014-08-16 17:57:50 -0700 |
---|---|---|
committer | Torsten Marek <shlomme@gmail.com> | 2014-08-16 17:57:50 -0700 |
commit | 20ffb646e24da344602c705be938f2f6baac0494 (patch) | |
tree | d60869fe55b36338461b872a138dc0c53160fa44 | |
parent | d4695d4fd8b50df7840c6e7e4b4a9103c37388dc (diff) | |
download | pylint-20ffb646e24da344602c705be938f2f6baac0494.tar.gz |
Extend the reporter interface with a method that takes a message object, for better extendability.
-rw-r--r-- | reporters/__init__.py | 11 | ||||
-rw-r--r-- | reporters/guireporter.py | 5 | ||||
-rw-r--r-- | reporters/html.py | 4 | ||||
-rw-r--r-- | reporters/text.py | 18 | ||||
-rw-r--r-- | test/test_functional.py | 4 | ||||
-rw-r--r-- | test/test_self.py | 4 | ||||
-rw-r--r-- | utils.py | 4 |
7 files changed, 26 insertions, 24 deletions
diff --git a/reporters/__init__.py b/reporters/__init__.py index 28d7071..f22653e 100644 --- a/reporters/__init__.py +++ b/reporters/__init__.py @@ -60,9 +60,16 @@ class BaseReporter(object): # Build the path prefix to strip to get relative paths self.path_strip_prefix = os.getcwd() + os.sep + def handle_message(self, msg): + """Handle a new message triggered on the current file. + + Invokes the legacy add_message API by default.""" + self.add_message( + msg.msg_id, (msg.abspath, msg.module, msg.obj, msg.line, msg.column), + msg.msg) + def add_message(self, msg_id, location, msg): - """Client API to send a message""" - # Shall we store the message objects somewhere, do some validity checking ? + """Deprecated, do not use.""" raise NotImplementedError def set_output(self, output=None): diff --git a/reporters/guireporter.py b/reporters/guireporter.py index 8ebc270..f908f76 100644 --- a/reporters/guireporter.py +++ b/reporters/guireporter.py @@ -19,10 +19,9 @@ class GUIReporter(BaseReporter): BaseReporter.__init__(self, output) self.gui = gui - def add_message(self, msg_id, location, msg): + def handle_message(self, msg): """manage message of different type and in the context of path""" - message = utils.Message(msg_id, self.linter.msgs_store.check_message_id(msg_id).symbol, location, msg) - self.gui.msg_queue.put(message) + self.gui.msg_queue.put(msg) def _display(self, layout): """launch layouts display""" diff --git a/reporters/html.py b/reporters/html.py index 441f68a..3e5a1a7 100644 --- a/reporters/html.py +++ b/reporters/html.py @@ -34,10 +34,8 @@ class HTMLReporter(BaseReporter): BaseReporter.__init__(self, output) self.msgs = [] - def add_message(self, msg_id, location, msg): + def handle_message(self, msg): """manage message of different type and in the context of path""" - msg = utils.Message(msg_id, self.linter.msgs_store.check_message_id(msg_id).symbol, - location, msg) self.msgs += (msg.category, msg.module, msg.obj, str(msg.line), str(msg.column), escape(msg.msg)) diff --git a/reporters/text.py b/reporters/text.py index 83bfe60..48b5155 100644 --- a/reporters/text.py +++ b/reporters/text.py @@ -24,7 +24,6 @@ from logilab.common.textutils import colorize_ansi from pylint.interfaces import IReporter from pylint.reporters import BaseReporter -from pylint import utils TITLE_UNDERLINES = ['', '=', '-', '.'] @@ -49,17 +48,15 @@ class TextReporter(BaseReporter): """Convenience method to write a formated message with class default template""" self.writeln(msg.format(self._template)) - def add_message(self, msg_id, location, msg): + def handle_message(self, msg): """manage message of different type and in the context of path""" - m = utils.Message(msg_id, self.linter.msgs_store.check_message_id(msg_id).symbol, - location, msg) - if m.module not in self._modules: - if m.module: - self.writeln('************* Module %s' % m.module) - self._modules.add(m.module) + if msg.module not in self._modules: + if msg.module: + self.writeln('************* Module %s' % msg.module) + self._modules.add(msg.module) else: self.writeln('************* ') - self.write_message(m) + self.write_message(msg) def _display(self, layout): """launch layouts display""" @@ -116,11 +113,10 @@ class ColorizedTextReporter(TextReporter): except KeyError: return None, None - def add_message(self, msg_id, location, msg): + def handle_message(self, msg): """manage message of different types, and colorize output using ansi escape codes """ - msg = utils.Message(msg_id, self.linter.msgs_store.check_message_id(msg_id).symbol, location, msg) if msg.module not in self._modules: color, style = self._get_decoration('S') if msg.module: diff --git a/test/test_functional.py b/test/test_functional.py index a6c6780..daf699f 100644 --- a/test/test_functional.py +++ b/test/test_functional.py @@ -48,8 +48,8 @@ def parse_python_version(str): class TestReporter(reporters.BaseReporter): - def add_message(self, msg_id, location, msg): - self.messages.append(utils.Message(msg_id, self.linter.msgs_store.check_message_id(msg_id).symbol, location, msg)) + def handle_message(self, msg): + self.messages.append(msg) def on_set_current_module(self, module, filepath): self.messages = [] diff --git a/test/test_self.py b/test/test_self.py index 4935f8a..7eb3261 100644 --- a/test/test_self.py +++ b/test/test_self.py @@ -33,9 +33,9 @@ class MultiReporter(BaseReporter): for rep in self._reporters: rep.on_set_current_module(*args, **kwargs) - def add_message(self, *args, **kwargs): + def handle_message(self, msg): for rep in self._reporters: - rep.add_message(*args, **kwargs) + rep.handle_message(msg) def display_results(self, layout): pass @@ -376,7 +376,9 @@ class MessagesHandlerMixIn(object): module, obj = get_module_and_frameid(node) path = node.root().file # add the message - self.reporter.add_message(msgid, (path, module, obj, line or 1, col_offset or 0), msg) + self.reporter.handle_message( + Message(msgid, symbol, + (path, module, obj, line or 1, col_offset or 0), msg)) def print_full_documentation(self): """output a full documentation in ReST format""" |