Skip to content

Commit c48188a

Browse files
[bad-option-value] Add a 'useless-option-value' message
So it's possible to to distinguish between genuine typoes and old configuration that could be cleaned.
1 parent 1d50219 commit c48188a

18 files changed

+86
-20
lines changed

.pyenchant_pylint_custom_dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ typechecking
324324
typeddict
325325
typehint
326326
typeshed
327+
typoes
327328
uid
328329
uml
329330
un

doc/whatsnew/2/2.14/full.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Release date: TBA
1717

1818
Closes #6810
1919

20+
* Deleted messages that do not exists anymore in pylint now raise ``useless-option-value`` instead of ``bad-option-value``
21+
which permit to distinguish between genuine typoes and old configuration that could be cleaned.
22+
23+
Refs #6794
2024

2125
What's New in Pylint 2.14.0?
2226
----------------------------

pylint/lint/message_state_handler.py

Lines changed: 8 additions & 2 deletions
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,14 @@ 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}."
415+
(
416+
symbol,
417+
msg,
418+
) = self.linter.msgs_store.kwargs_for_bad_option_value_add_message(
419+
msgid, f"'{pragma_repr.action}'"
420+
)
415421
self.linter.add_message(
416-
"bad-option-value", args=msg, line=start[0]
422+
line=start[0], confidence=HIGH, msgid=symbol, args=msg
417423
)
418424
except UnRecognizedOptionError as err:
419425
self.linter.add_message(

pylint/lint/pylinter.py

Lines changed: 12 additions & 2 deletions
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
@@ -194,6 +195,13 @@ def _load_reporter_by_class(reporter_class: str) -> type[BaseReporter]:
194195
"Used when a bad value for an inline option is encountered.",
195196
{"scope": WarningScope.LINE},
196197
),
198+
"I0012": (
199+
"Useless option value for %s",
200+
"useless-option-value",
201+
"Used when a value for an inline option that is now deleted from pylint"
202+
" is encountered.",
203+
{"scope": WarningScope.LINE},
204+
),
197205
"E0013": (
198206
"Plugin '%s' is impossible to load, is it installed ? ('%s')",
199207
"bad-plugin-value",
@@ -1206,6 +1214,8 @@ def _emit_bad_option_value(self) -> None:
12061214
self.linter.set_current_module(modname)
12071215
values = self._stashed_bad_option_value_messages[modname]
12081216
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)
1217+
symbol, msg = self.msgs_store.kwargs_for_bad_option_value_add_message(
1218+
msg_id, f"'{option_string}'"
1219+
)
1220+
self.add_message(line=0, msgid=symbol, args=msg, confidence=HIGH)
12111221
self._stashed_bad_option_value_messages = collections.defaultdict(list)

pylint/message/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
44

55
"""All the classes related to Message handling."""
6-
76
from pylint.message.message import Message
87
from pylint.message.message_definition import MessageDefinition
98
from pylint.message.message_definition_store import MessageDefinitionStore

pylint/message/message_definition_store.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from collections.abc import Sequence, ValuesView
1010
from typing import TYPE_CHECKING
1111

12+
from pylint.constants import DELETED_MESSAGES
1213
from pylint.exceptions import UnknownMessageError
1314
from pylint.message.message_definition import MessageDefinition
1415
from pylint.message.message_id_store import MessageIdStore
@@ -32,6 +33,28 @@ def __init__(self) -> None:
3233
# MessageDefinition kept by category
3334
self._msgs_by_category: dict[str, list[str]] = collections.defaultdict(list)
3435

36+
@staticmethod
37+
def is_deleted_msgid_or_symbol(msgid_or_symbol: str) -> str | None:
38+
"""Return the explanation for removal if the message was removed."""
39+
for explanation, deleted_messages in DELETED_MESSAGES.items():
40+
for deleted_message in deleted_messages:
41+
if msgid_or_symbol in [deleted_message.msgid, deleted_message.symbol]:
42+
return explanation
43+
return None
44+
45+
def kwargs_for_bad_option_value_add_message(
46+
self, msgid: str, original_message: str
47+
) -> tuple[str, str]:
48+
removal_explanation = self.is_deleted_msgid_or_symbol(msgid)
49+
if removal_explanation is not None:
50+
symbol = "useless-option-value"
51+
msg = f"{original_message}. '{msgid}' was removed from pylint, see {removal_explanation}."
52+
else:
53+
symbol = "bad-option-value"
54+
msg = f"{original_message}. Don't recognize message '{msgid}'."
55+
56+
return symbol, msg
57+
3558
@property
3659
def messages(self) -> ValuesView[MessageDefinition]:
3760
"""The list of all active messages."""
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
************* Module {abspath}
2+
{relpath}:1:0: I0012: Useless option value for '--disable'. 'buffer-builtin' was removed from pylint, see https://github.com/PyCQA/pylint/pull/4942. (useless-option-value)
3+
{relpath}:1:0: I0012: Useless option value for '--enable'. 'cmp-builtin' was removed from pylint, see https://github.com/PyCQA/pylint/pull/4942. (useless-option-value)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Check that we raise an informational when a deleted messages exists in a .pylintrc file
2+
# See https://github.com/PyCQA/pylint/issues/6794
3+
[messages control]
4+
disable = logging-not-lazy, buffer-builtin
5+
enable = useless-option-value, locally-disabled, cmp-builtin
6+
jobs = 10
7+
reports = yes
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"functional_append": {
3+
"disable": ["logging-not-lazy"],
4+
"enable": ["locally-disabled", "useless-option-value"]
5+
},
6+
"functional_remove": {
7+
"disable": ["locally-disabled", "useless-option-value"],
8+
"enable": ["logging-not-lazy"]
9+
},
10+
"jobs": 10,
11+
"reports": true
12+
}
Lines changed: 2 additions & 2 deletions
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'. 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)
Lines changed: 1 addition & 1 deletion
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'. Don't recognize message 'useless-supression'. (bad-option-value)
Lines changed: 2 additions & 2 deletions
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'. 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)
Lines changed: 2 additions & 2 deletions
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'. 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)

tests/config/test_config.py

Lines changed: 1 addition & 1 deletion
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:
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1+
"""Check unknown option. """
2+
13
# pylint:enable=W04044 # [bad-option-value]
2-
"""check unknown option
3-
"""
4-
__revision__ = 1
4+
# pylint:enable=execfile-builtin # [useless-option-value]
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
bad-option-value:1:0:None:None::Bad option value for enable. Don't recognize message W04044.:UNDEFINED
1+
bad-option-value:3:0:None:None::Bad option value for 'enable'. Don't recognize message 'W04044'.:HIGH
2+
useless-option-value:4:0:None:None::"Useless option value for 'enable'. 'execfile-builtin' was removed from pylint, see https://github.com/PyCQA/pylint/pull/4942.":HIGH
Lines changed: 2 additions & 2 deletions
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'. Don't recognize message 'a-removed-option'.:HIGH
2+
bad-option-value:13:0:None:None::Bad option value for 'disable'. Don't recognize message 'a-removed-option'.:HIGH

tests/functional/u/use/use_symbolic_message_instead.txt

Lines changed: 1 addition & 1 deletion
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'. Don't recognize message '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)