From 988d882b56f9eca8ba1825b86b59e92b824ca1c3 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Wed, 15 Jun 2022 01:57:32 -0400 Subject: [PATCH] Treat `--errors-only` as a disable, not a paired enable/disable (#6937) Co-authored-by: Pierre Sassoulas --- doc/whatsnew/2/2.14/full.rst | 5 +++++ pylint/lint/base_options.py | 6 +++--- pylint/lint/message_state_handler.py | 11 ++++------- tests/test_self.py | 10 ++++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/doc/whatsnew/2/2.14/full.rst b/doc/whatsnew/2/2.14/full.rst index ec17330678..1d9578b20a 100644 --- a/doc/whatsnew/2/2.14/full.rst +++ b/doc/whatsnew/2/2.14/full.rst @@ -34,6 +34,11 @@ Release date: TBA * Fixed a false positive for ``used-before-assignment`` when a try block returns but an except handler defines a name via type annotation. +* ``--errors-only`` no longer enables previously disabled messages. It was acting as + "emit *all* and only error messages" without being clearly documented that way. + + Closes #6811 + What's New in Pylint 2.14.1? diff --git a/pylint/lint/base_options.py b/pylint/lint/base_options.py index aab019044d..25327e635e 100644 --- a/pylint/lint/base_options.py +++ b/pylint/lint/base_options.py @@ -529,9 +529,9 @@ def _make_run_options(self: Run) -> Options: "action": _ErrorsOnlyModeAction, "kwargs": {"Run": self}, "short": "E", - "help": "In error mode, checkers without error messages are " - "disabled and for others, only the ERROR messages are " - "displayed, and no reports are done by default.", + "help": "In error mode, messages with a category besides " + "ERROR or FATAL are suppressed, and no reports are done by default. " + "Error mode is compatible with disabling specific errors. ", "hide_from_config_file": True, }, ), diff --git a/pylint/lint/message_state_handler.py b/pylint/lint/message_state_handler.py index 6e30453d9a..8415c88544 100644 --- a/pylint/lint/message_state_handler.py +++ b/pylint/lint/message_state_handler.py @@ -227,14 +227,11 @@ def enable( self._register_by_id_managed_msg(msgid, line, is_disabled=False) def disable_noerror_messages(self) -> None: - for msgcat, msgids in self.linter.msgs_store._msgs_by_category.items(): - # enable only messages with 'error' severity and above ('fatal') + """Disable message categories other than `error` and `fatal`.""" + for msgcat in self.linter.msgs_store._msgs_by_category: if msgcat in {"E", "F"}: - for msgid in msgids: - self.enable(msgid) - else: - for msgid in msgids: - self.disable(msgid) + continue + self.disable(msgcat) def list_messages_enabled(self) -> None: emittable, non_emittable = self.linter.msgs_store.find_emittable_messages() diff --git a/tests/test_self.py b/tests/test_self.py index 38dea42575..67d89d3710 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -1519,6 +1519,16 @@ def test_errors_only() -> None: run = Run(["--errors-only"]) assert run.linter._error_mode + @staticmethod + def test_errors_only_functions_as_disable() -> None: + """--errors-only functions as a shortcut for --disable=W,C,R,I; + it no longer enables any messages.""" + run = Run( + [str(UNNECESSARY_LAMBDA), "--disable=import-error", "--errors-only"], + do_exit=False, + ) + assert not run.linter.is_message_enabled("import-error") + @staticmethod def test_verbose() -> None: """Test the --verbose flag."""