Skip to content

Commit

Permalink
Treat --errors-only as a disable, not a paired enable/disable (#6937)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
jacobtylerwalls and Pierre-Sassoulas committed Jun 15, 2022
1 parent 386e778 commit 988d882
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
6 changes: 3 additions & 3 deletions pylint/lint/base_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
),
Expand Down
11 changes: 4 additions & 7 deletions pylint/lint/message_state_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 988d882

Please sign in to comment.