Coverage for C:\Repos\ekr-pylint\pylint\lint\report_functions.py: 20%
44 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
« 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
5from __future__ import annotations
7import collections
8from collections import defaultdict
10from pylint import checkers, exceptions
11from pylint.reporters.ureports.nodes import Section, Table
12from pylint.utils import LinterStats
15def report_total_messages_stats(
16 sect: Section,
17 stats: LinterStats,
18 previous_stats: LinterStats | None,
19) -> None:
20 """Make total errors / warnings report."""
21 lines = ["type", "number", "previous", "difference"]
22 lines += checkers.table_lines_from_stats(stats, previous_stats, "message_types")
23 sect.append(Table(children=lines, cols=4, rheaders=1))
26def report_messages_stats(
27 sect: Section,
28 stats: LinterStats,
29 _: LinterStats | None,
30) -> None:
31 """Make messages type report."""
32 by_msg_stats = stats.by_msg
33 in_order = sorted(
34 (value, msg_id)
35 for msg_id, value in by_msg_stats.items()
36 if not msg_id.startswith("I")
37 )
38 in_order.reverse()
39 lines = ["message id", "occurrences"]
40 for value, msg_id in in_order:
41 lines += [msg_id, str(value)]
42 sect.append(Table(children=lines, cols=2, rheaders=1))
45def report_messages_by_module_stats(
46 sect: Section,
47 stats: LinterStats,
48 _: LinterStats | None,
49) -> None:
50 """Make errors / warnings by modules report."""
51 module_stats = stats.by_module
52 if len(module_stats) == 1:
53 # don't print this report when we are analysing a single module
54 raise exceptions.EmptyReportError()
55 by_mod: defaultdict[str, dict[str, int | float]] = collections.defaultdict(dict)
56 for m_type in ("fatal", "error", "warning", "refactor", "convention"):
57 total = stats.get_global_message_count(m_type)
58 for module in module_stats.keys():
59 mod_total = stats.get_module_message_count(module, m_type)
60 percent = 0 if total == 0 else float(mod_total * 100) / total
61 by_mod[module][m_type] = percent
62 sorted_result = []
63 for module, mod_info in by_mod.items():
64 sorted_result.append(
65 (
66 mod_info["error"],
67 mod_info["warning"],
68 mod_info["refactor"],
69 mod_info["convention"],
70 module,
71 )
72 )
73 sorted_result.sort()
74 sorted_result.reverse()
75 lines = ["module", "error", "warning", "refactor", "convention"]
76 for line in sorted_result:
77 # Don't report clean modules.
78 if all(entry == 0 for entry in line[:-1]):
79 continue
80 lines.append(line[-1])
81 for val in line[:-1]:
82 lines.append(f"{val:.2f}")
83 if len(lines) == 5:
84 raise exceptions.EmptyReportError()
85 sect.append(Table(children=lines, cols=5, rheaders=1))