Coverage for C:\Repos\ekr-pylint\pylint\reporters\json_reporter.py: 72%

18 statements  

« prev     ^ index     » next       coverage.py v6.4, created at 2022-05-24 10:21 -0500

1# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html 

2# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE 

3# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt 

4 

5"""JSON reporter.""" 

6 

7from __future__ import annotations 

8 

9import json 

10from typing import TYPE_CHECKING 

11 

12from pylint.reporters.base_reporter import BaseReporter 

13 

14if TYPE_CHECKING: 

15 from pylint.lint.pylinter import PyLinter 

16 from pylint.reporters.ureports.nodes import Section 

17 

18 

19class JSONReporter(BaseReporter): 

20 """Report messages and layouts in JSON.""" 

21 

22 name = "json" 

23 extension = "json" 

24 

25 def display_messages(self, layout: Section | None) -> None: 

26 """Launch layouts display.""" 

27 json_dumpable = [ 

28 { 

29 "type": msg.category, 

30 "module": msg.module, 

31 "obj": msg.obj, 

32 "line": msg.line, 

33 "column": msg.column, 

34 "endLine": msg.end_line, 

35 "endColumn": msg.end_column, 

36 "path": msg.path, 

37 "symbol": msg.symbol, 

38 "message": msg.msg or "", 

39 "message-id": msg.msg_id, 

40 } 

41 for msg in self.messages 

42 ] 

43 print(json.dumps(json_dumpable, indent=4), file=self.out) 

44 

45 def display_reports(self, layout: Section) -> None: 

46 """Don't do anything in this reporter.""" 

47 

48 def _display(self, layout: Section) -> None: 

49 """Do nothing.""" 

50 

51 

52def register(linter: PyLinter) -> None: 

53 linter.register_reporter(JSONReporter)