Skip to content

Commit 0b41dfc

Browse files
[bad-option-value] Use the right confidence and refactor message (#6829)
Co-authored-by: Daniël van Noord <[email protected]>
1 parent 6fac84e commit 0b41dfc

12 files changed

+44
-29
lines changed

pylint/lint/message_state_handler.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
MSG_TYPES,
1818
MSG_TYPES_LONG,
1919
)
20+
from pylint.interfaces import HIGH
2021
from pylint.message import MessageDefinition
2122
from pylint.typing import ManagedMessage
2223
from pylint.utils.pragma_parser import (
@@ -411,9 +412,11 @@ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None:
411412
try:
412413
meth(msgid, "module", l_start)
413414
except exceptions.UnknownMessageError:
414-
msg = f"{pragma_repr.action}. Don't recognize message {msgid}."
415415
self.linter.add_message(
416-
"bad-option-value", args=msg, line=start[0]
416+
"bad-option-value",
417+
args=(pragma_repr.action, msgid),
418+
line=start[0],
419+
confidence=HIGH,
417420
)
418421
except UnRecognizedOptionError as err:
419422
self.linter.add_message(

pylint/lint/pylinter.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
MSG_TYPES_STATUS,
3030
WarningScope,
3131
)
32+
from pylint.interfaces import HIGH
3233
from pylint.lint.base_options import _make_linter_options
3334
from pylint.lint.caching import load_results, save_results
3435
from pylint.lint.expand_modules import _is_ignored_file, expand_modules
@@ -189,9 +190,9 @@ def _load_reporter_by_class(reporter_class: str) -> type[BaseReporter]:
189190
{"scope": WarningScope.LINE},
190191
),
191192
"E0012": (
192-
"Bad option value for %s",
193+
"Bad option value for '%s', expected a valid pylint message and got '%s'",
193194
"bad-option-value",
194-
"Used when a bad value for an inline option is encountered.",
195+
"Used when a bad value for an option is encountered.",
195196
{"scope": WarningScope.LINE},
196197
),
197198
"E0013": (
@@ -1206,6 +1207,10 @@ def _emit_bad_option_value(self) -> None:
12061207
self.linter.set_current_module(modname)
12071208
values = self._stashed_bad_option_value_messages[modname]
12081209
for option_string, msg_id in values:
1209-
msg = f"{option_string}. Don't recognize message {msg_id}."
1210-
self.add_message("bad-option-value", args=msg, line=0)
1210+
self.add_message(
1211+
"bad-option-value",
1212+
args=(option_string, msg_id),
1213+
line=0,
1214+
confidence=HIGH,
1215+
)
12111216
self._stashed_bad_option_value_messages = collections.defaultdict(list)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
************* Module {abspath}
2-
{relpath}:1:0: E0012: Bad option value for --disable. Don't recognize message buffer-builtin. (bad-option-value)
3-
{relpath}:1:0: E0012: Bad option value for --enable. Don't recognize message useless-option-value. (bad-option-value)
4-
{relpath}:1:0: E0012: Bad option value for --enable. Don't recognize message cmp-builtin. (bad-option-value)
2+
{relpath}:1:0: E0012: Bad option value for '--disable', expected a valid pylint message and got 'buffer-builtin' (bad-option-value)
3+
{relpath}:1:0: E0012: Bad option value for '--enable', expected a valid pylint message and got 'useless-option-value' (bad-option-value)
4+
{relpath}:1:0: E0012: Bad option value for '--enable', expected a valid pylint message and got 'cmp-builtin' (bad-option-value)
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
************* Module {abspath}
2-
{relpath}:1:0: E0012: Bad option value for --disable. Don't recognize message logging-not-lazylogging-format-interpolation. (bad-option-value)
3-
{relpath}:1:0: E0012: Bad option value for --enable. Don't recognize message locally-disabledsuppressed-message. (bad-option-value)
2+
{relpath}:1:0: E0012: Bad option value for '--disable', expected a valid pylint message and got 'logging-not-lazylogging-format-interpolation' (bad-option-value)
3+
{relpath}:1:0: E0012: Bad option value for '--enable', expected a valid pylint message and got 'locally-disabledsuppressed-message' (bad-option-value)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
************* Module {abspath}
2-
{relpath}:1:0: E0012: Bad option value for --enable. Don't recognize message useless-supression. (bad-option-value)
2+
{relpath}:1:0: E0012: Bad option value for '--enable', expected a valid pylint message and got 'useless-supression' (bad-option-value)
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
************* Module {abspath}
2-
{relpath}:1:0: E0012: Bad option value for --disable. Don't recognize message logging-not-lazylogging-format-interpolation. (bad-option-value)
3-
{relpath}:1:0: E0012: Bad option value for --enable. Don't recognize message locally-disabledsuppressed-message. (bad-option-value)
2+
{relpath}:1:0: E0012: Bad option value for '--disable', expected a valid pylint message and got 'logging-not-lazylogging-format-interpolation' (bad-option-value)
3+
{relpath}:1:0: E0012: Bad option value for '--enable', expected a valid pylint message and got 'locally-disabledsuppressed-message' (bad-option-value)
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
************* Module {abspath}
2-
{relpath}:1:0: E0012: Bad option value for --disable. Don't recognize message logging-not-layzy. (bad-option-value)
3-
{relpath}:1:0: E0012: Bad option value for --enable. Don't recognize message C00000. (bad-option-value)
2+
{relpath}:1:0: E0012: Bad option value for '--disable', expected a valid pylint message and got 'logging-not-layzy' (bad-option-value)
3+
{relpath}:1:0: E0012: Bad option value for '--enable', expected a valid pylint message and got 'C00000' (bad-option-value)

tests/config/test_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_unknown_message_id(capsys: CaptureFixture) -> None:
6060
"""Check that we correctly raise a message on an unknown id."""
6161
Run([str(EMPTY_MODULE), "--disable=12345"], exit=False)
6262
output = capsys.readouterr()
63-
assert "Command line:1:0: E0012: Bad option value for --disable." in output.out
63+
assert "Command line:1:0: E0012: Bad option value for '--disable'" in output.out
6464

6565

6666
def test_unknown_option_name(capsys: CaptureFixture) -> None:

tests/functional/b/bad_option_value.py

+5
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@
1919
# pylint:enable=no-space-after-comma # [bad-option-value]
2020
# enable with deleted msgid
2121
# pylint:enable=W1622 # [bad-option-value]
22+
23+
# Standard disable with deleted old name symbol of deleted message
24+
# pylint: disable=no-space-after-operator # [bad-option-value]
25+
# Standard disable with deleted old name msgid of deleted message
26+
# pylint: disable=C0323 # [bad-option-value]
+11-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
bad-option-value:4:0:None:None::Bad option value for disable. Don't recognize message C05048.:UNDEFINED
2-
bad-option-value:6:0:None:None::Bad option value for disable. Don't recognize message execfile-builtin.:UNDEFINED
3-
bad-option-value:8:0:None:None::Bad option value for disable. Don't recognize message W1656.:UNDEFINED
4-
bad-option-value:10:0:None:None::Bad option value for disable-next. Don't recognize message R78948.:UNDEFINED
5-
bad-option-value:12:0:None:None::Bad option value for disable-next. Don't recognize message deprecated-types-field.:UNDEFINED
6-
bad-option-value:14:0:None:None::Bad option value for disable-next. Don't recognize message W1634.:UNDEFINED
7-
bad-option-value:17:0:None:None::Bad option value for enable. Don't recognize message W04044.:UNDEFINED
8-
bad-option-value:19:0:None:None::Bad option value for enable. Don't recognize message no-space-after-comma.:UNDEFINED
9-
bad-option-value:21:0:None:None::Bad option value for enable. Don't recognize message W1622.:UNDEFINED
1+
bad-option-value:4:0:None:None::Bad option value for 'disable', expected a valid pylint message and got 'C05048':HIGH
2+
bad-option-value:6:0:None:None::Bad option value for 'disable', expected a valid pylint message and got 'execfile-builtin':HIGH
3+
bad-option-value:8:0:None:None::Bad option value for 'disable', expected a valid pylint message and got 'W1656':HIGH
4+
bad-option-value:10:0:None:None::Bad option value for 'disable-next', expected a valid pylint message and got 'R78948':HIGH
5+
bad-option-value:12:0:None:None::Bad option value for 'disable-next', expected a valid pylint message and got 'deprecated-types-field':HIGH
6+
bad-option-value:14:0:None:None::Bad option value for 'disable-next', expected a valid pylint message and got 'W1634':HIGH
7+
bad-option-value:17:0:None:None::Bad option value for 'enable', expected a valid pylint message and got 'W04044':HIGH
8+
bad-option-value:19:0:None:None::Bad option value for 'enable', expected a valid pylint message and got 'no-space-after-comma':HIGH
9+
bad-option-value:21:0:None:None::Bad option value for 'enable', expected a valid pylint message and got 'W1622':HIGH
10+
bad-option-value:24:0:None:None::Bad option value for 'disable', expected a valid pylint message and got 'no-space-after-operator':HIGH
11+
bad-option-value:26:0:None:None::Bad option value for 'disable', expected a valid pylint message and got 'C0323':HIGH
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
bad-option-value:10:0:None:None::Bad option value for disable. Don't recognize message a-removed-option.:UNDEFINED
2-
bad-option-value:13:0:None:None::Bad option value for disable. Don't recognize message a-removed-option.:UNDEFINED
1+
bad-option-value:10:0:None:None::Bad option value for 'disable', expected a valid pylint message and got 'a-removed-option':HIGH
2+
bad-option-value:13:0:None:None::Bad option value for 'disable', expected a valid pylint message and got 'a-removed-option':HIGH

tests/functional/u/use/use_symbolic_message_instead.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
bad-option-value:1:0:None:None::Bad option value for disable. Don't recognize message T1234.:UNDEFINED
1+
bad-option-value:1:0:None:None::Bad option value for 'disable', expected a valid pylint message and got 'T1234':HIGH
22
use-symbolic-message-instead:1:0:None:None::"'C0111' is cryptic: use '# pylint: disable=missing-docstring' instead":UNDEFINED
33
use-symbolic-message-instead:1:0:None:None::"'R0903' is cryptic: use '# pylint: disable=too-few-public-methods' instead":UNDEFINED
44
use-symbolic-message-instead:2:0:None:None::"'c0111' is cryptic: use '# pylint: enable=missing-docstring' instead":UNDEFINED

0 commit comments

Comments
 (0)