From daef49a9f5623a324f65f5227f2e4a2f7cfeeff0 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Sat, 29 Sep 2018 16:06:59 +0200 Subject: ``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 --- ChangeLog | 4 ++++ pylint/test/functional/control_pragmas.py | 19 +++++++++++++++++++ pylint/test/functional/control_pragmas.txt | 0 pylint/utils.py | 4 ++-- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 pylint/test/functional/control_pragmas.py create mode 100644 pylint/test/functional/control_pragmas.txt 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 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" -- cgit v1.2.1