summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-09-29 16:06:59 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2018-09-29 16:08:15 +0200
commitdaef49a9f5623a324f65f5227f2e4a2f7cfeeff0 (patch)
treee9f99928f6a71b7926c62132796533e9a023e66e
parent5d066ed8c8850dcf2a814f849c8b19c1bfd603a1 (diff)
downloadpylint-git-daef49a9f5623a324f65f5227f2e4a2f7cfeeff0.tar.gz
``pylint`` is less eager to consume the whole line for pragmas
The regex was adapted so that we either stop at one of `;` or `#`, or at the end of the line. This should improve the situation a little bit when dealing with the flags of other linters. Close #2485
-rw-r--r--ChangeLog4
-rw-r--r--pylint/test/functional/control_pragmas.py19
-rw-r--r--pylint/test/functional/control_pragmas.txt0
-rw-r--r--pylint/utils.py4
4 files changed, 25 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 1d95f4bb5..f82efb5f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,10 @@ What's New in Pylint 2.2?
Release date: TBA
+ * ``pylint`` is less eager to consume the whole line for pragmas
+
+ Close #2485
+
* Change ``unbalanced-tuple-unpacking`` back to a warning.
It used to be a warning until a couple of years ago, after it was promoted to
diff --git a/pylint/test/functional/control_pragmas.py b/pylint/test/functional/control_pragmas.py
new file mode 100644
index 000000000..993f9a5dd
--- /dev/null
+++ b/pylint/test/functional/control_pragmas.py
@@ -0,0 +1,19 @@
+# pylint: disable=missing-docstring
+
+
+def test_pragma():
+ """Test that the control pragmas are not too eager to consume the entire line
+
+ We should stop either at:
+ - ; or #
+ - or at the end of line
+ """
+ # noqa: E501 # pylint: disable=unused-variable #nosec
+ variable = 1
+
+ # noqa # pylint: disable=undefined-variable,no-member; don't trigger
+ other_variable = some_variable + variable.member
+
+ # noqa # pylint: disable=unbalanced-tuple-unpacking,no-member # no trigger
+ first, second = some_other_variable
+ return first + other_variable.method()
diff --git a/pylint/test/functional/control_pragmas.txt b/pylint/test/functional/control_pragmas.txt
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/pylint/test/functional/control_pragmas.txt
diff --git a/pylint/utils.py b/pylint/utils.py
index fb7075c9c..76afdea09 100644
--- a/pylint/utils.py
+++ b/pylint/utils.py
@@ -78,10 +78,10 @@ MSG_STATE_SCOPE_CONFIG = 0
MSG_STATE_SCOPE_MODULE = 1
MSG_STATE_CONFIDENCE = 2
-# Allow stopping after the first semicolon encountered,
+# Allow stopping after the first semicolon/hash encountered,
# so that an option can be continued with the reasons
# why it is active or disabled.
-OPTION_RGX = re.compile(r"\s*#.*\bpylint:\s*([^;]+);{0,1}")
+OPTION_RGX = re.compile(r"\s*#.*\bpylint:\s*([^;#]+)[;#]{0,1}")
# The line/node distinction does not apply to fatal errors and reports.
_SCOPE_EXEMPT = "FR"