Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/9898.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
colorized reporter now colorizes messages/categories that have been configured as `fail-on` in red inverse.
This makes it easier to quickly find the errors that are causing pylint CI job failures.

Closes #9898
3 changes: 3 additions & 0 deletions pylint/config/config_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def _config_initialization( # pylint: disable=too-many-statements
# enable them
linter.enable_fail_on_messages()

# Now that fail_on messages are enabled, pass them to colorized reporter
linter.pass_fail_on_config_to_color_reporter()

linter._parse_error_mode()

# Link the base Namespace object on the current directory
Expand Down
11 changes: 10 additions & 1 deletion pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from pylint.message import Message, MessageDefinition, MessageDefinitionStore
from pylint.reporters.base_reporter import BaseReporter
from pylint.reporters.progress_reporters import ProgressReporter
from pylint.reporters.text import TextReporter
from pylint.reporters.text import ColorizedTextReporter, TextReporter
from pylint.reporters.ureports import nodes as report_nodes
from pylint.typing import (
DirectoryNamespaceDict,
Expand Down Expand Up @@ -531,6 +531,15 @@
def any_fail_on_issues(self) -> bool:
return any(x in self.fail_on_symbols for x in self.stats.by_msg.keys())

def pass_fail_on_config_to_color_reporter(self) -> None:
"""Pass fail_on symbol configuration to colorized text reporter."""
if isinstance(self.reporter, ColorizedTextReporter):
self.reporter.set_fail_on_symbols(self.fail_on_symbols)
elif isinstance(self.reporter, reporters.MultiReporter):
for _reporter in self.reporter._sub_reporters:
if isinstance(self.reporter, ColorizedTextReporter):
self.reporter.set_fail_on_symbols(self.fail_on_symbols)

Check warning on line 541 in pylint/lint/pylinter.py

View check run for this annotation

Codecov / codecov/patch

pylint/lint/pylinter.py#L539-L541

Added lines #L539 - L541 were not covered by tests

def disable_reporters(self) -> None:
"""Disable all reporters."""
for _reporters in self._reports.values():
Expand Down
11 changes: 10 additions & 1 deletion pylint/reporters/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
"W": MessageStyle("magenta"),
"E": MessageStyle("red", ("bold",)),
"F": MessageStyle("red", ("bold", "underline")),
"X": MessageStyle("red", ("bold", "inverse")),
"S": MessageStyle("yellow", ("inverse",)), # S stands for module Separator
}

Expand All @@ -225,6 +226,7 @@
) -> None:
super().__init__(output)
self.color_mapping = color_mapping or ColorizedTextReporter.COLOR_MAPPING
self.fail_on_symbols: list[str] = []
ansi_terms = ["xterm-16color", "xterm-256color"]
if os.environ.get("TERM") not in ansi_terms:
if sys.platform == "win32":
Expand All @@ -237,6 +239,10 @@
"""Returns the message style as defined in self.color_mapping."""
return self.color_mapping.get(msg_id[0]) or MessageStyle(None)

def set_fail_on_symbols(self, fail_on_symbols: list[str]) -> None:
"""Sets the list of configured fail-on symbols."""
self.fail_on_symbols = fail_on_symbols

def handle_message(self, msg: Message) -> None:
"""Manage message of different types, and colorize output
using ANSI escape codes.
Expand All @@ -246,7 +252,10 @@
modsep = colorize_ansi(make_header(msg), msg_style)
self.writeln(modsep)
self._modules.add(msg.module)
msg_style = self._get_decoration(msg.C)
if msg.symbol in self.fail_on_symbols:
msg_style = self._get_decoration("X")

Check warning on line 256 in pylint/reporters/text.py

View check run for this annotation

Codecov / codecov/patch

pylint/reporters/text.py#L256

Added line #L256 was not covered by tests
else:
msg_style = self._get_decoration(msg.C)

msg.msg = colorize_ansi(msg.msg, msg_style)
msg.symbol = colorize_ansi(msg.symbol, msg_style)
Expand Down