Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat --errors-only as a disable, not a paired enable/disable #6937

Merged
merged 4 commits into from
Jun 15, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved

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