From fe0a7f7953430f10308d2ba94c14f056e166fe1c Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Sun, 7 Jun 2020 22:51:23 -0700 Subject: Allow numbers in checker names. (#3667) This fixes https://github.com/PyCQA/pylint/issues/3666. --- CONTRIBUTORS.txt | 2 ++ ChangeLog | 4 ++++ pylint/utils/pragma_parser.py | 2 +- tests/test_pragma_parser.py | 8 ++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 4dc47f901..9b3c69550 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -385,3 +385,5 @@ contributors: * Damien Baty: contributor * Daniel R. Neal (danrneal): contributer + +* Jeremy Fleischman (jfly): contributer diff --git a/ChangeLog b/ChangeLog index 94d8f5f2e..214a47604 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ What's New in Pylint 2.6.0? =========================== Release date: TBA +* Fix a regression where disable comments that have checker names with numbers in them are not parsed correctly + + Close #3666 + * bad-continuation and bad-whitespace have been removed, black or another formatter can help you with this better than Pylint Close #246, #289, #638, #747, #1148, #1179, #1943, #2041, #2301, #2304, #2944, #3565 diff --git a/pylint/utils/pragma_parser.py b/pylint/utils/pragma_parser.py index 28f04b668..2afbae5a3 100644 --- a/pylint/utils/pragma_parser.py +++ b/pylint/utils/pragma_parser.py @@ -39,7 +39,7 @@ ALL_KEYWORDS = "|".join( TOKEN_SPECIFICATION = [ ("KEYWORD", r"\b({:s})\b".format(ALL_KEYWORDS)), - ("MESSAGE_STRING", r"[A-Za-z\-\_]{2,}"), #  Identifiers + ("MESSAGE_STRING", r"[0-9A-Za-z\-\_]{2,}"), #  Identifiers ("ASSIGN", r"="), #  Assignment operator ("MESSAGE_NUMBER", r"[CREIWF]{1}\d*"), ] diff --git a/tests/test_pragma_parser.py b/tests/test_pragma_parser.py index 1e5b16b28..0dec8ac88 100644 --- a/tests/test_pragma_parser.py +++ b/tests/test_pragma_parser.py @@ -16,6 +16,14 @@ def test_simple_pragma(): assert pragma_repr.messages == ["missing-docstring"] +def test_disable_checker_with_number_in_name(): + comment = "#pylint: disable = j3-custom-checker" + match = OPTION_PO.search(comment) + for pragma_repr in parse_pragma(match.group(2)): + assert pragma_repr.action == "disable" + assert pragma_repr.messages == ["j3-custom-checker"] + + def test_simple_pragma_no_messages(): comment = "#pylint: skip-file" match = OPTION_PO.search(comment) -- cgit v1.2.1