From 6e1635c48b711fed6cf1d523b5f77da343824f71 Mon Sep 17 00:00:00 2001 From: clavedeluna Date: Fri, 2 Dec 2022 08:40:13 -0300 Subject: [PATCH 1/3] add test and expl for line-too-long useless-supp FP --- doc/data/messages/l/line-too-long/details.rst | 3 +++ doc/whatsnew/fragments/3368.false_positive | 2 ++ tests/data/line_too_long_no_code.py | 1 + tests/test_self.py | 15 +++++++++++++++ 4 files changed, 21 insertions(+) create mode 100644 doc/data/messages/l/line-too-long/details.rst create mode 100644 doc/whatsnew/fragments/3368.false_positive create mode 100644 tests/data/line_too_long_no_code.py diff --git a/doc/data/messages/l/line-too-long/details.rst b/doc/data/messages/l/line-too-long/details.rst new file mode 100644 index 0000000000..e18621bda1 --- /dev/null +++ b/doc/data/messages/l/line-too-long/details.rst @@ -0,0 +1,3 @@ +If you attempt to disable this message via ``# pylint: disable=line-too-long`` in a module with no code, you may receive a message for ``useless-suppression``. This is a currently acceptable false positive for ``useless-suppression``. + +See https://github.com/PyCQA/pylint/issues/3368 for more information. diff --git a/doc/whatsnew/fragments/3368.false_positive b/doc/whatsnew/fragments/3368.false_positive new file mode 100644 index 0000000000..22310bc8e2 --- /dev/null +++ b/doc/whatsnew/fragments/3368.false_positive @@ -0,0 +1,2 @@ +Document an acceptable false positive for ``useless-suppression`` when disabling ``line-too-long`` in a module with only comments and no code. +Closes #3368 diff --git a/tests/data/line_too_long_no_code.py b/tests/data/line_too_long_no_code.py new file mode 100644 index 0000000000..28f30c57f2 --- /dev/null +++ b/tests/data/line_too_long_no_code.py @@ -0,0 +1 @@ +# ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 # pylint: disable=line-too-long diff --git a/tests/test_self.py b/tests/test_self.py index 587b8bb589..76bf41c4fb 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -1247,6 +1247,21 @@ def test_encoding(self, module_name: str, expected_output: str) -> None: [path], expected_output=expected_output, unexpected_output="(astroid-error)" ) + def test_line_too_long_useless_suppression(self) -> None: + """A test that demonstrates an acceptable false positive for useless-suppression + + See https://github.com/PyCQA/pylint/issues/3368 + """ + module = join(HERE, "data", "line_too_long_no_code.py") + expected = textwrap.dedent( + f""" + {module}:1:0: I0011: Locally disabling line-too-long (C0301) (locally-disabled) + {module}:1:0: I0021: Useless suppression of 'line-too-long' (useless-suppression) + """ + ) + + self._test_output([module, "--enable=all"], expected_output=expected) + class TestCallbackOptions: """Test for all callback options we support.""" From 8ab6f4bfbbaba79745a1c2b6b48f0b1c4758ab35 Mon Sep 17 00:00:00 2001 From: Dani Alcala <112832187+clavedeluna@users.noreply.github.com> Date: Fri, 2 Dec 2022 09:34:20 -0300 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Pierre Sassoulas --- doc/data/messages/l/line-too-long/details.rst | 2 +- doc/whatsnew/fragments/3368.false_positive | 3 ++- tests/data/line_too_long_no_code.py | 1 + tests/test_self.py | 14 ++------------ 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/doc/data/messages/l/line-too-long/details.rst b/doc/data/messages/l/line-too-long/details.rst index e18621bda1..068a453b48 100644 --- a/doc/data/messages/l/line-too-long/details.rst +++ b/doc/data/messages/l/line-too-long/details.rst @@ -1,3 +1,3 @@ -If you attempt to disable this message via ``# pylint: disable=line-too-long`` in a module with no code, you may receive a message for ``useless-suppression``. This is a currently acceptable false positive for ``useless-suppression``. +If you attempt to disable this message via ``# pylint: disable=line-too-long`` in a module with no code, you may receive a message for ``useless-suppression``. This is a false positive of ``useless-suppression`` we can't easily fix. See https://github.com/PyCQA/pylint/issues/3368 for more information. diff --git a/doc/whatsnew/fragments/3368.false_positive b/doc/whatsnew/fragments/3368.false_positive index 22310bc8e2..bdfa7de6c7 100644 --- a/doc/whatsnew/fragments/3368.false_positive +++ b/doc/whatsnew/fragments/3368.false_positive @@ -1,2 +1,3 @@ -Document an acceptable false positive for ``useless-suppression`` when disabling ``line-too-long`` in a module with only comments and no code. +Document a known false positive for ``useless-suppression`` when disabling ``line-too-long`` in a module with only comments and no code. + Closes #3368 diff --git a/tests/data/line_too_long_no_code.py b/tests/data/line_too_long_no_code.py index 28f30c57f2..75ab07fc2e 100644 --- a/tests/data/line_too_long_no_code.py +++ b/tests/data/line_too_long_no_code.py @@ -1 +1,2 @@ # ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 # pylint: disable=line-too-long +# See https://github.com/PyCQA/pylint/issues/3368 diff --git a/tests/test_self.py b/tests/test_self.py index 76bf41c4fb..81947a5a97 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -1247,20 +1247,10 @@ def test_encoding(self, module_name: str, expected_output: str) -> None: [path], expected_output=expected_output, unexpected_output="(astroid-error)" ) + @pytest.mark.xfail(reason="See https://github.com/PyCQA/pylint/issues/3368") def test_line_too_long_useless_suppression(self) -> None: - """A test that demonstrates an acceptable false positive for useless-suppression - - See https://github.com/PyCQA/pylint/issues/3368 - """ module = join(HERE, "data", "line_too_long_no_code.py") - expected = textwrap.dedent( - f""" - {module}:1:0: I0011: Locally disabling line-too-long (C0301) (locally-disabled) - {module}:1:0: I0021: Useless suppression of 'line-too-long' (useless-suppression) - """ - ) - - self._test_output([module, "--enable=all"], expected_output=expected) + self._test_output([module, "--enable=all"], expected_output="") class TestCallbackOptions: From ce016f9719c1a082fb0782d0900bce82e591f703 Mon Sep 17 00:00:00 2001 From: clavedeluna Date: Fri, 2 Dec 2022 19:11:15 -0300 Subject: [PATCH 3/3] add test and comment --- .../line_too_long_no_code.py | 0 tests/test_self.py | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) rename tests/{data => regrtest_data}/line_too_long_no_code.py (100%) diff --git a/tests/data/line_too_long_no_code.py b/tests/regrtest_data/line_too_long_no_code.py similarity index 100% rename from tests/data/line_too_long_no_code.py rename to tests/regrtest_data/line_too_long_no_code.py diff --git a/tests/test_self.py b/tests/test_self.py index 81947a5a97..02e1a17e83 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -1247,10 +1247,23 @@ def test_encoding(self, module_name: str, expected_output: str) -> None: [path], expected_output=expected_output, unexpected_output="(astroid-error)" ) - @pytest.mark.xfail(reason="See https://github.com/PyCQA/pylint/issues/3368") def test_line_too_long_useless_suppression(self) -> None: - module = join(HERE, "data", "line_too_long_no_code.py") - self._test_output([module, "--enable=all"], expected_output="") + """A test that demonstrates a known false positive for useless-suppression + + See https://github.com/PyCQA/pylint/issues/3368 + + If you manage to make this test fail and remove the useless-suppression + warning please contact open a Pylint PR! + """ + module = join(HERE, "regrtest_data", "line_too_long_no_code.py") + expected = textwrap.dedent( + f""" + {module}:1:0: I0011: Locally disabling line-too-long (C0301) (locally-disabled) + {module}:1:0: I0021: Useless suppression of 'line-too-long' (useless-suppression) + """ + ) + + self._test_output([module, "--enable=all"], expected_output=expected) class TestCallbackOptions: