summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-07-07 19:42:51 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2022-07-17 21:44:17 +0200
commit8af7472a41675be709a54aa30506c5c150d6df51 (patch)
treee6b31fa1f29f46ad9c7d4a599114be7747845b59
parenteac2e0419133e87aa059de2e66e4339135e5e53f (diff)
downloadpylint-git-8af7472a41675be709a54aa30506c5c150d6df51.tar.gz
Fix disabling of ``fixme`` (#7144)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
-rw-r--r--doc/data/messages/f/fixme/bad.py5
-rw-r--r--doc/data/messages/f/fixme/details.rst3
-rw-r--r--doc/data/messages/f/fixme/good.py6
-rw-r--r--doc/whatsnew/2/2.14/full.rst3
-rw-r--r--pylint/checkers/misc.py42
-rw-r--r--tests/functional/f/fixme.py14
-rw-r--r--tests/functional/f/fixme.rc1
7 files changed, 33 insertions, 41 deletions
diff --git a/doc/data/messages/f/fixme/bad.py b/doc/data/messages/f/fixme/bad.py
new file mode 100644
index 000000000..d646cf994
--- /dev/null
+++ b/doc/data/messages/f/fixme/bad.py
@@ -0,0 +1,5 @@
+# FIXME: Create an issue on the bug tracker for this refactor we might do someday # [fixme]
+
+...
+
+# TODO: We should also fix this at some point # [fixme]
diff --git a/doc/data/messages/f/fixme/details.rst b/doc/data/messages/f/fixme/details.rst
index ab8204529..02869b537 100644
--- a/doc/data/messages/f/fixme/details.rst
+++ b/doc/data/messages/f/fixme/details.rst
@@ -1 +1,2 @@
-You can help us make the doc better `by contributing <https://github.com/PyCQA/pylint/issues/5953>`_ !
+You can get use regular expressions and the ``notes-rgx`` option to create some constraints for this message.
+See `the following issue <https://github.com/PyCQA/pylint/issues/2874>`_ for some examples.
diff --git a/doc/data/messages/f/fixme/good.py b/doc/data/messages/f/fixme/good.py
index c40beb573..d3d816cbe 100644
--- a/doc/data/messages/f/fixme/good.py
+++ b/doc/data/messages/f/fixme/good.py
@@ -1 +1,5 @@
-# This is a placeholder for correct code for this message.
+# I no longer want to fix this
+
+...
+
+# I have fixed the issue
diff --git a/doc/whatsnew/2/2.14/full.rst b/doc/whatsnew/2/2.14/full.rst
index 10073abc2..edc5fa4c7 100644
--- a/doc/whatsnew/2/2.14/full.rst
+++ b/doc/whatsnew/2/2.14/full.rst
@@ -15,6 +15,9 @@ Release date: TBA
Closes #7003
+* Fixed the disabling of ``fixme`` and its interaction with ``useless-suppression``.
+
+
What's New in Pylint 2.14.4?
----------------------------
Release date: 2022-06-29
diff --git a/pylint/checkers/misc.py b/pylint/checkers/misc.py
index 623db8c78..b48d302d8 100644
--- a/pylint/checkers/misc.py
+++ b/pylint/checkers/misc.py
@@ -14,7 +14,6 @@ from astroid import nodes
from pylint.checkers import BaseRawFileChecker, BaseTokenChecker
from pylint.typing import ManagedMessage
-from pylint.utils.pragma_parser import OPTION_PO, PragmaParserError, parse_pragma
if TYPE_CHECKING:
from pylint.lint import PyLinter
@@ -134,45 +133,16 @@ class EncodingChecker(BaseTokenChecker, BaseRawFileChecker):
"""Inspect the source to find fixme problems."""
if not self.linter.config.notes:
return
- comments = (
- token_info for token_info in tokens if token_info.type == tokenize.COMMENT
- )
- for comment in comments:
- comment_text = comment.string[1:].lstrip() # trim '#' and white-spaces
-
- # handle pylint disable clauses
- disable_option_match = OPTION_PO.search(comment_text)
- if disable_option_match:
- try:
- values = []
- try:
- for pragma_repr in (
- p_rep
- for p_rep in parse_pragma(disable_option_match.group(2))
- if p_rep.action == "disable"
- ):
- values.extend(pragma_repr.messages)
- except PragmaParserError:
- # Printing useful information dealing with this error is done in the lint package
- pass
- except ValueError:
- self.add_message(
- "bad-inline-option",
- args=disable_option_match.group(1).strip(),
- line=comment.start[0],
- )
- continue
- self.linter.add_ignored_message("fixme", line=comment.start[0])
+ for token_info in tokens:
+ if token_info.type != tokenize.COMMENT:
continue
-
- # emit warnings if necessary
- match = self._fixme_pattern.search("#" + comment_text.lower())
- if match:
+ comment_text = token_info.string[1:].lstrip() # trim '#' and white-spaces
+ if self._fixme_pattern.search("#" + comment_text.lower()):
self.add_message(
"fixme",
- col_offset=comment.start[1] + 1,
+ col_offset=token_info.start[1] + 1,
args=comment_text,
- line=comment.start[0],
+ line=token_info.start[0],
)
diff --git a/tests/functional/f/fixme.py b/tests/functional/f/fixme.py
index 081d508f4..e3d420f8e 100644
--- a/tests/functional/f/fixme.py
+++ b/tests/functional/f/fixme.py
@@ -1,5 +1,5 @@
-# -*- encoding=utf-8 -*-
-# pylint: disable=missing-docstring, unused-variable
+"""Tests for fixme and its disabling and enabling."""
+# pylint: disable=missing-function-docstring, unused-variable
# +1: [fixme]
# FIXME: beep
@@ -29,5 +29,13 @@ def function():
#FIXME: in fact nothing to fix #pylint: disable=fixme
#TODO: in fact nothing to do #pylint: disable=fixme
- #TODO: in fact nothing to do #pylint: disable=line-too-long, fixme
+ #TODO: in fact nothing to do #pylint: disable=line-too-long, fixme, useless-suppression
# Todoist API mentioned should not result in a message.
+
+# pylint: disable-next=fixme
+# FIXME: Don't raise when the message is disabled
+
+# This line needs to be at the end of the file to make sure it doesn't end with a comment
+# Pragma's compare against the 'lineno' attribute of the respective nodes which
+# would stop too soon otherwise.
+print()
diff --git a/tests/functional/f/fixme.rc b/tests/functional/f/fixme.rc
index be1b23458..a1a5e600b 100644
--- a/tests/functional/f/fixme.rc
+++ b/tests/functional/f/fixme.rc
@@ -3,3 +3,4 @@
notes=XXX,TODO,./TODO
# Regular expression of note tags to take in consideration.
notes-rgx=FIXME(?!.*ISSUE-\d+)|TO.*DO
+enable=useless-suppression