From 8af7472a41675be709a54aa30506c5c150d6df51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 7 Jul 2022 19:42:51 +0200 Subject: [PATCH] Fix disabling of ``fixme`` (#7144) Co-authored-by: Pierre Sassoulas --- doc/data/messages/f/fixme/bad.py | 5 ++++ doc/data/messages/f/fixme/details.rst | 3 +- doc/data/messages/f/fixme/good.py | 6 +++- doc/whatsnew/2/2.14/full.rst | 3 ++ pylint/checkers/misc.py | 42 ++++----------------------- tests/functional/f/fixme.py | 14 +++++++-- tests/functional/f/fixme.rc | 1 + 7 files changed, 33 insertions(+), 41 deletions(-) create mode 100644 doc/data/messages/f/fixme/bad.py diff --git a/doc/data/messages/f/fixme/bad.py b/doc/data/messages/f/fixme/bad.py new file mode 100644 index 0000000000..d646cf9941 --- /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 ab82045295..02869b5374 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 `_ ! +You can get use regular expressions and the ``notes-rgx`` option to create some constraints for this message. +See `the following issue `_ for some examples. diff --git a/doc/data/messages/f/fixme/good.py b/doc/data/messages/f/fixme/good.py index c40beb573f..d3d816cbe1 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 10073abc26..edc5fa4c7e 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 623db8c78e..b48d302d8c 100644 --- a/pylint/checkers/misc.py +++ b/pylint/checkers/misc.py @@ -14,7 +14,6 @@ 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 @@ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None: """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 081d508f43..e3d420f8ef 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 be1b23458e..a1a5e600ba 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