summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2020-05-14 19:03:24 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2020-05-14 19:03:24 +0200
commit5cbdd9430313fcfb339f3a6c24d91629e2ed365b (patch)
treef30484a84b1b74ca5ae8e557df222311fe1f78f1
parent62edb5893b547d71651283f1b7c6c58b929a75da (diff)
downloadpylint-git-5cbdd9430313fcfb339f3a6c24d91629e2ed365b.tar.gz
Fix a regression where messages with dash are not fully parsed
Close #3604
-rw-r--r--ChangeLog4
-rw-r--r--pylint/utils/pragma_parser.py4
-rw-r--r--tests/test_pragma_parser.py8
3 files changed, 14 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 37441019a..94cd76238 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,10 @@ Release date: TBA
Close #3612
+* Fix a regression where messages with dash are not fully parsed
+
+ Close #3604
+
What's New in Pylint 2.5.2?
===========================
diff --git a/pylint/utils/pragma_parser.py b/pylint/utils/pragma_parser.py
index 4b3fb301a..28f04b668 100644
--- a/pylint/utils/pragma_parser.py
+++ b/pylint/utils/pragma_parser.py
@@ -17,7 +17,7 @@ OPTION_RGX = r"""
.*? # Anything (as little as possible)
\bpylint: # pylint word and column
\s* # Any number of whitespaces
- ([^;#\n]+)) # Anything except semicolon or hash or newline (it is the second matched group)
+ ([^;#\n]+)) # Anything except semicolon or hash or newline (it is the second matched group)
# and end of the first matched group
[;#]{0,1}""" # From 0 to 1 repetition of semicolon or hash
OPTION_PO = re.compile(OPTION_RGX, re.VERBOSE)
@@ -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"[A-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 1aaed30d5..1e5b16b28 100644
--- a/tests/test_pragma_parser.py
+++ b/tests/test_pragma_parser.py
@@ -82,3 +82,11 @@ def test_missing_message():
match = OPTION_PO.search(comment)
with pytest.raises(InvalidPragmaError):
list(parse_pragma(match.group(2)))
+
+
+def test_parse_message_with_dash():
+ comment = "#pylint: disable = raw_input-builtin"
+ match = OPTION_PO.search(comment)
+ res = list(parse_pragma(match.group(2)))
+ assert res[0].action == "disable"
+ assert res[0].messages == ["raw_input-builtin"]