Coverage for C:\Repos\ekr-pylint\pylint\checkers\__init__.py: 39%
36 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
5"""Utilities methods and classes for checkers.
7Base id of standard checkers (used in msg and report ids):
801: base
902: classes
1003: format
1104: import
1205: misc
1306: variables
1407: exceptions
1508: similar
1609: design_analysis
1710: newstyle
1811: typecheck
1912: logging
2013: string_format
2114: string_constant
2215: stdlib
2316: python3 (This one was deleted but needs to be reserved for consistency with old messages)
2417: refactoring
25.
26.
27.
2824: non-ascii-names
2925: unicode
3026: unsupported_version
3127: private-import
3228-50: not yet used: reserved for future internal checkers.
33This file is not updated. Use
34 script/get_unused_message_id_category.py
35to get the next free checker id.
3751-99: perhaps used: reserved for external checkers
39The raw_metrics checker has no number associated since it doesn't emit any
40messages nor reports. XXX not true, emit a 07 report !
42"""
44from __future__ import annotations
46import sys
47from typing import TYPE_CHECKING
49from pylint.checkers.base_checker import (
50 BaseChecker,
51 BaseRawFileChecker,
52 BaseTokenChecker,
53)
54from pylint.checkers.deprecated import DeprecatedMixin
55from pylint.checkers.mapreduce_checker import MapReduceMixin
56from pylint.utils import LinterStats, diff_string, register_plugins
58if sys.version_info >= (3, 8):
59 from typing import Literal
60else:
61 from typing_extensions import Literal
63if TYPE_CHECKING:
64 from pylint.lint import PyLinter
67def table_lines_from_stats(
68 stats: LinterStats,
69 old_stats: LinterStats | None,
70 stat_type: Literal["duplicated_lines", "message_types"],
71) -> list[str]:
72 """Get values listed in <columns> from <stats> and <old_stats>,
73 and return a formatted list of values.
75 The return value is designed to be given to a ureport.Table object
76 """
77 lines: list[str] = []
78 if stat_type == "duplicated_lines":
79 new: list[tuple[str, int | float]] = [
80 ("nb_duplicated_lines", stats.duplicated_lines["nb_duplicated_lines"]),
81 (
82 "percent_duplicated_lines",
83 stats.duplicated_lines["percent_duplicated_lines"],
84 ),
85 ]
86 if old_stats:
87 old: list[tuple[str, str | int | float]] = [
88 (
89 "nb_duplicated_lines",
90 old_stats.duplicated_lines["nb_duplicated_lines"],
91 ),
92 (
93 "percent_duplicated_lines",
94 old_stats.duplicated_lines["percent_duplicated_lines"],
95 ),
96 ]
97 else:
98 old = [("nb_duplicated_lines", "NC"), ("percent_duplicated_lines", "NC")]
99 elif stat_type == "message_types":
100 new = [
101 ("convention", stats.convention),
102 ("refactor", stats.refactor),
103 ("warning", stats.warning),
104 ("error", stats.error),
105 ]
106 if old_stats:
107 old = [
108 ("convention", old_stats.convention),
109 ("refactor", old_stats.refactor),
110 ("warning", old_stats.warning),
111 ("error", old_stats.error),
112 ]
113 else:
114 old = [
115 ("convention", "NC"),
116 ("refactor", "NC"),
117 ("warning", "NC"),
118 ("error", "NC"),
119 ]
121 for index, value in enumerate(new):
122 new_value = value[1]
123 old_value = old[index][1]
124 diff_str = (
125 diff_string(old_value, new_value)
126 if isinstance(old_value, float)
127 else old_value
128 )
129 new_str = f"{new_value:.3f}" if isinstance(new_value, float) else str(new_value)
130 old_str = f"{old_value:.3f}" if isinstance(old_value, float) else str(old_value)
131 lines.extend((value[0].replace("_", " "), new_str, old_str, diff_str))
132 return lines
135def initialize(linter: PyLinter) -> None:
136 """Initialize linter with checkers in this package."""
137 register_plugins(linter, __path__[0])
140__all__ = [
141 "BaseChecker",
142 "BaseTokenChecker",
143 "BaseRawFileChecker",
144 "initialize",
145 "MapReduceMixin",
146 "DeprecatedMixin",
147 "register_plugins",
148]