Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

json.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (c) 2014 Vlad Temian <vladtemian@gmail.com>
  2. # Copyright (c) 2015-2017 Claudiu Popa <pcmanticore@gmail.com>
  3. # Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
  4. # Copyright (c) 2017 guillaume2 <guillaume.peillex@gmail.col>
  5. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  6. # For details: https://github.com/PyCQA/pylint/blob/master/COPYING
  7. """JSON reporter"""
  8. from __future__ import absolute_import, print_function
  9. import cgi
  10. import json
  11. import sys
  12. from pylint.interfaces import IReporter
  13. from pylint.reporters import BaseReporter
  14. class JSONReporter(BaseReporter):
  15. """Report messages and layouts in JSON."""
  16. __implements__ = IReporter
  17. name = 'json'
  18. extension = 'json'
  19. def __init__(self, output=sys.stdout):
  20. BaseReporter.__init__(self, output)
  21. self.messages = []
  22. def handle_message(self, msg):
  23. """Manage message of different type and in the context of path."""
  24. self.messages.append({
  25. 'type': msg.category,
  26. 'module': msg.module,
  27. 'obj': msg.obj,
  28. 'line': msg.line,
  29. 'column': msg.column,
  30. 'path': msg.path,
  31. 'symbol': msg.symbol,
  32. # pylint: disable=deprecated-method; deprecated since 3.2.
  33. 'message': cgi.escape(msg.msg or ''),
  34. 'message-id': msg.msg_id,
  35. })
  36. def display_messages(self, layout):
  37. """Launch layouts display"""
  38. if self.messages:
  39. print(json.dumps(self.messages, indent=4), file=self.out)
  40. def display_reports(self, layout): # pylint: disable=arguments-differ
  41. """Don't do nothing in this reporter."""
  42. def _display(self, layout):
  43. """Don't do nothing."""
  44. def register(linter):
  45. """Register the reporter classes with the linter."""
  46. linter.register_reporter(JSONReporter)