Skip to content

Commit 988d882

Browse files
Treat --errors-only as a disable, not a paired enable/disable (#6937)
Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent 386e778 commit 988d882

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

doc/whatsnew/2/2.14/full.rst

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ Release date: TBA
3434
* Fixed a false positive for ``used-before-assignment`` when a try block returns
3535
but an except handler defines a name via type annotation.
3636

37+
* ``--errors-only`` no longer enables previously disabled messages. It was acting as
38+
"emit *all* and only error messages" without being clearly documented that way.
39+
40+
Closes #6811
41+
3742

3843

3944
What's New in Pylint 2.14.1?

pylint/lint/base_options.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,9 @@ def _make_run_options(self: Run) -> Options:
529529
"action": _ErrorsOnlyModeAction,
530530
"kwargs": {"Run": self},
531531
"short": "E",
532-
"help": "In error mode, checkers without error messages are "
533-
"disabled and for others, only the ERROR messages are "
534-
"displayed, and no reports are done by default.",
532+
"help": "In error mode, messages with a category besides "
533+
"ERROR or FATAL are suppressed, and no reports are done by default. "
534+
"Error mode is compatible with disabling specific errors. ",
535535
"hide_from_config_file": True,
536536
},
537537
),

pylint/lint/message_state_handler.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,11 @@ def enable(
227227
self._register_by_id_managed_msg(msgid, line, is_disabled=False)
228228

229229
def disable_noerror_messages(self) -> None:
230-
for msgcat, msgids in self.linter.msgs_store._msgs_by_category.items():
231-
# enable only messages with 'error' severity and above ('fatal')
230+
"""Disable message categories other than `error` and `fatal`."""
231+
for msgcat in self.linter.msgs_store._msgs_by_category:
232232
if msgcat in {"E", "F"}:
233-
for msgid in msgids:
234-
self.enable(msgid)
235-
else:
236-
for msgid in msgids:
237-
self.disable(msgid)
233+
continue
234+
self.disable(msgcat)
238235

239236
def list_messages_enabled(self) -> None:
240237
emittable, non_emittable = self.linter.msgs_store.find_emittable_messages()

tests/test_self.py

+10
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,16 @@ def test_errors_only() -> None:
15191519
run = Run(["--errors-only"])
15201520
assert run.linter._error_mode
15211521

1522+
@staticmethod
1523+
def test_errors_only_functions_as_disable() -> None:
1524+
"""--errors-only functions as a shortcut for --disable=W,C,R,I;
1525+
it no longer enables any messages."""
1526+
run = Run(
1527+
[str(UNNECESSARY_LAMBDA), "--disable=import-error", "--errors-only"],
1528+
do_exit=False,
1529+
)
1530+
assert not run.linter.is_message_enabled("import-error")
1531+
15221532
@staticmethod
15231533
def test_verbose() -> None:
15241534
"""Test the --verbose flag."""

0 commit comments

Comments
 (0)