OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2003-2014 LOGILAB S.A. (Paris, FRANCE). |
| 2 # This program is free software; you can redistribute it and/or modify it under |
| 3 # the terms of the GNU General Public License as published by the Free Software |
| 4 # Foundation; either version 2 of the License, or (at your option) any later |
| 5 # version. |
| 6 # |
| 7 # This program is distributed in the hope that it will be useful, but WITHOUT |
| 8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 9 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 10 # |
| 11 # You should have received a copy of the GNU General Public License along with |
| 12 # this program; if not, write to the Free Software Foundation, Inc., |
| 13 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 14 """JSON reporter""" |
| 15 from __future__ import absolute_import, print_function |
| 16 |
| 17 import json |
| 18 import sys |
| 19 from cgi import escape |
| 20 |
| 21 from pylint.interfaces import IReporter |
| 22 from pylint.reporters import BaseReporter |
| 23 |
| 24 |
| 25 class JSONReporter(BaseReporter): |
| 26 """Report messages and layouts in JSON.""" |
| 27 |
| 28 __implements__ = IReporter |
| 29 name = 'json' |
| 30 extension = 'json' |
| 31 |
| 32 def __init__(self, output=sys.stdout): |
| 33 BaseReporter.__init__(self, output) |
| 34 self.messages = [] |
| 35 |
| 36 def handle_message(self, message): |
| 37 """Manage message of different type and in the context of path.""" |
| 38 |
| 39 self.messages.append({ |
| 40 'type': message.category, |
| 41 'module': message.module, |
| 42 'obj': message.obj, |
| 43 'line': message.line, |
| 44 'column': message.column, |
| 45 'path': message.path, |
| 46 'symbol': message.symbol, |
| 47 'message': escape(message.msg or ''), |
| 48 }) |
| 49 |
| 50 def _display(self, layout): |
| 51 """Launch layouts display""" |
| 52 if self.messages: |
| 53 print(json.dumps(self.messages, indent=4), file=self.out) |
| 54 |
| 55 |
| 56 def register(linter): |
| 57 """Register the reporter classes with the linter.""" |
| 58 linter.register_reporter(JSONReporter) |
OLD | NEW |