summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordbrookman <53625739+dbrookman@users.noreply.github.com>2022-03-04 03:20:58 -0500
committerGitHub <noreply@github.com>2022-03-04 09:20:58 +0100
commita1df7685a4e6a05b519ea011f16a2f0d49d08032 (patch)
treecea3593787f7fe1181dd25fec693d45c43777075
parent182cc539b8154c0710fcea7e522267e42eba8899 (diff)
downloadpylint-git-a1df7685a4e6a05b519ea011f16a2f0d49d08032.tar.gz
Fix matching note tags with a non-word char last (#5859)
Using "\b" at the end of these patterns will only match note tags that end in an alphanumeric character, immediately followed by a non-alphanumeric character, or the end of the string. This is due to "\b" being defined as a boundary between a word character ("\w") and a non-word character ("\W"), or the end of the string. This leads to deviations like "???" being ignored when specified. Swapping "\b" for a positive lookahead that targets a whitespace, a colon, or the end of a string accounts for this. Closes #5840.
-rw-r--r--CONTRIBUTORS.txt2
-rw-r--r--ChangeLog4
-rw-r--r--doc/whatsnew/2.13.rst4
-rw-r--r--pylint/checkers/misc.py4
-rw-r--r--tests/checkers/unittest_misc.py10
5 files changed, 22 insertions, 2 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index 66480ea6a..88ab429cf 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -601,3 +601,5 @@ contributors:
* Carli Freudenberg (CarliJoy): contributor
- Fixed issue 5281, added Unicode checker
- Improve non-ascii-name checker
+
+* Daniel Brookman: contributor
diff --git a/ChangeLog b/ChangeLog
index b6ba4becf..fc5d18485 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,10 @@ Release date: TBA
..
Put new features here and also in 'doc/whatsnew/2.13.rst'
+* Fix matching ``--notes`` options that end in a non-word character.
+
+ Closes #5840
+
* ``using-f-string-in-unsupported-version`` and ``using-final-decorator-in-unsupported-version`` msgids
were renamed from ``W1601`` and ``W1602`` to ``W2601`` and ``W2602``. Disabling using these msgids will break.
This is done in order to restore consistency with the already existing msgids for ``apply-builtin`` and
diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst
index 21f13c004..4954cada4 100644
--- a/doc/whatsnew/2.13.rst
+++ b/doc/whatsnew/2.13.rst
@@ -92,6 +92,10 @@ Extensions
Other Changes
=============
+* Fix matching ``--notes`` options that end in a non-word character.
+
+ Closes #5840
+
* ``using-f-string-in-unsupported-version`` and ``using-final-decorator-in-unsupported-version`` msgids
were renamed from ``W1601`` and ``W1602`` to ``W2601`` and ``W2602``. Disables using these msgids will break.
This is done in order to restore consistency with the already existing msgids for ``apply-builtin`` and
diff --git a/pylint/checkers/misc.py b/pylint/checkers/misc.py
index 69149e61a..baec58fbb 100644
--- a/pylint/checkers/misc.py
+++ b/pylint/checkers/misc.py
@@ -121,9 +121,9 @@ class EncodingChecker(BaseChecker):
notes = "|".join(re.escape(note) for note in self.config.notes)
if self.config.notes_rgx:
- regex_string = rf"#\s*({notes}|{self.config.notes_rgx})\b"
+ regex_string = rf"#\s*({notes}|{self.config.notes_rgx})(?=(:|\s|\Z))"
else:
- regex_string = rf"#\s*({notes})\b"
+ regex_string = rf"#\s*({notes})(?=(:|\s|\Z))"
self._fixme_pattern = re.compile(regex_string, re.I)
diff --git a/tests/checkers/unittest_misc.py b/tests/checkers/unittest_misc.py
index 23e19a9d0..bd15a932e 100644
--- a/tests/checkers/unittest_misc.py
+++ b/tests/checkers/unittest_misc.py
@@ -68,6 +68,16 @@ class TestFixme(CheckerTestCase):
):
self.checker.process_tokens(_tokenize_str(code))
+ @set_config(notes=["???"])
+ def test_non_alphanumeric_codetag(self) -> None:
+ code = """a = 1
+ #???
+ """
+ with self.assertAddsMessages(
+ MessageTest(msg_id="fixme", line=2, args="???", col_offset=17)
+ ):
+ self.checker.process_tokens(_tokenize_str(code))
+
@set_config(notes=[])
def test_absent_codetag(self) -> None:
code = """a = 1