Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / reporters / json.py @ 745

History | View | Annotate | Download (2.15 KB)

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 cgi
18
import json
19
import sys
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
        self.messages.append({
39
            'type': message.category,
40
            'module': message.module,
41
            'obj': message.obj,
42
            'line': message.line,
43
            'column': message.column,
44
            'path': message.path,
45
            'symbol': message.symbol,
46
            # pylint: disable=deprecated-method; deprecated since 3.2.
47
            'message': cgi.escape(message.msg or ''),
48
        })
49

    
50
    def display_messages(self, layout):
51
        """Launch layouts display"""
52
        if self.messages:
53
            print(json.dumps(self.messages, indent=4), file=self.out)
54

    
55
    def display_reports(self, _):
56
        """Don't do nothing in this reporter."""
57

    
58
    def _display(self, layout):
59
        """Don't do nothing."""
60

    
61

    
62
def register(linter):
63
    """Register the reporter classes with the linter."""
64
    linter.register_reporter(JSONReporter)