diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2022-06-15 01:57:32 -0400 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2022-06-15 08:43:02 +0200 |
commit | 988d882b56f9eca8ba1825b86b59e92b824ca1c3 (patch) | |
tree | f808d2b944c3a6751ddb7d9d27e5624fcb81cb23 | |
parent | 386e7782b78a6e1baf0edd57cff893f3a08fb33c (diff) | |
download | pylint-git-988d882b56f9eca8ba1825b86b59e92b824ca1c3.tar.gz |
Treat `--errors-only` as a disable, not a paired enable/disable (#6937)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
-rw-r--r-- | doc/whatsnew/2/2.14/full.rst | 5 | ||||
-rw-r--r-- | pylint/lint/base_options.py | 6 | ||||
-rw-r--r-- | pylint/lint/message_state_handler.py | 11 | ||||
-rw-r--r-- | 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 ec1733067..1d9578b20 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 aab019044..25327e635 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 6e30453d9..8415c8854 100644 --- a/pylint/lint/message_state_handler.py +++ b/pylint/lint/message_state_handler.py @@ -227,14 +227,11 @@ class _MessageStateHandler: 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 38dea4257..67d89d371 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -1520,6 +1520,16 @@ class TestCallbackOptions: 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.""" with pytest.raises(SystemExit): |