diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2022-05-27 12:16:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-27 12:16:58 -0400 |
commit | a7ff1fd597f32686403b9f3a160b03dd55617d00 (patch) | |
tree | 0c7d66c3c473943d89e2032601edb812b6bb5c7b /pylint/lint | |
parent | a6a23ecabfd5cc7d43642013255b828ac85352d6 (diff) | |
download | pylint-git-a7ff1fd597f32686403b9f3a160b03dd55617d00.tar.gz |
Allow disabling `bad-option-value` and `unrecognized-option` with `--disable=all` (#6691)
Previously, due to the order in which options are parsed (config file, then command line), any unrecognized or bad options in the config file would emit messages unconditionally, even if suppressed on the CLI.
Diffstat (limited to 'pylint/lint')
-rw-r--r-- | pylint/lint/message_state_handler.py | 12 | ||||
-rw-r--r-- | pylint/lint/pylinter.py | 9 |
2 files changed, 21 insertions, 0 deletions
diff --git a/pylint/lint/message_state_handler.py b/pylint/lint/message_state_handler.py index 2477502bd..31278dc59 100644 --- a/pylint/lint/message_state_handler.py +++ b/pylint/lint/message_state_handler.py @@ -6,6 +6,7 @@ from __future__ import annotations import sys import tokenize +from collections import defaultdict from typing import TYPE_CHECKING from pylint import exceptions, interfaces @@ -53,6 +54,17 @@ class _MessageStateHandler: "enable-msg": self._options_methods["enable"], } self._pragma_lineno: dict[str, int] = {} + # TODO: 3.0: Update key type to str when current_name is always str + self._stashed_bad_option_value_messages: defaultdict[ + str | None, list[tuple[str | None, str]] + ] = defaultdict(list) + """Bad option values for --enable and --disable are encountered too early to + warn about them, i.e. before all option providers have been fully parsed. + + Thus, + this dict stores option_value and msg_id needed to (later) emit the + bad-option-value messages keyed on module names. + """ def _set_one_msg_status( self, scope: str, msg: MessageDefinition, line: int | None, enable: bool diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index 7ab822025..0dc9b8c0d 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -1196,3 +1196,12 @@ class PyLinter( message_definition.msgid, line, ) + + def _emit_bad_option_value(self) -> None: + for modname in self._stashed_bad_option_value_messages: + self.linter.set_current_module(modname) + values = self._stashed_bad_option_value_messages[modname] + for option_string, msg_id in values: + msg = f"{option_string}. Don't recognize message {msg_id}." + self.add_message("bad-option-value", args=msg, line=0) + self._stashed_bad_option_value_messages = collections.defaultdict(list) |