Skip to content

Commit

Permalink
Fix disabling of fixme (#7144)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
DanielNoord and Pierre-Sassoulas committed Jul 7, 2022
1 parent 41d4761 commit 3c34ae7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 41 deletions.
5 changes: 5 additions & 0 deletions 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]
3 changes: 2 additions & 1 deletion 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.
6 changes: 5 additions & 1 deletion 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
3 changes: 3 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Expand Up @@ -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
Expand Down
42 changes: 6 additions & 36 deletions pylint/checkers/misc.py
Expand Up @@ -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
Expand Down Expand Up @@ -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],
)


Expand Down
14 changes: 11 additions & 3 deletions 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
Expand Down Expand Up @@ -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()
1 change: 1 addition & 0 deletions tests/functional/f/fixme.rc
Expand Up @@ -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

0 comments on commit 3c34ae7

Please sign in to comment.