Skip to content

Commit 8af7472

Browse files
Fix disabling of fixme (#7144)
Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent eac2e04 commit 8af7472

File tree

7 files changed

+33
-41
lines changed

7 files changed

+33
-41
lines changed

doc/data/messages/f/fixme/bad.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# FIXME: Create an issue on the bug tracker for this refactor we might do someday # [fixme]
2+
3+
...
4+
5+
# TODO: We should also fix this at some point # [fixme]

doc/data/messages/f/fixme/details.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
You can help us make the doc better `by contributing <https://github.com/PyCQA/pylint/issues/5953>`_ !
1+
You can get use regular expressions and the ``notes-rgx`` option to create some constraints for this message.
2+
See `the following issue <https://github.com/PyCQA/pylint/issues/2874>`_ for some examples.

doc/data/messages/f/fixme/good.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# This is a placeholder for correct code for this message.
1+
# I no longer want to fix this
2+
3+
...
4+
5+
# I have fixed the issue

doc/whatsnew/2/2.14/full.rst

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Release date: TBA
1515

1616
Closes #7003
1717

18+
* Fixed the disabling of ``fixme`` and its interaction with ``useless-suppression``.
19+
20+
1821
What's New in Pylint 2.14.4?
1922
----------------------------
2023
Release date: 2022-06-29

pylint/checkers/misc.py

+6-36
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from pylint.checkers import BaseRawFileChecker, BaseTokenChecker
1616
from pylint.typing import ManagedMessage
17-
from pylint.utils.pragma_parser import OPTION_PO, PragmaParserError, parse_pragma
1817

1918
if TYPE_CHECKING:
2019
from pylint.lint import PyLinter
@@ -134,45 +133,16 @@ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None:
134133
"""Inspect the source to find fixme problems."""
135134
if not self.linter.config.notes:
136135
return
137-
comments = (
138-
token_info for token_info in tokens if token_info.type == tokenize.COMMENT
139-
)
140-
for comment in comments:
141-
comment_text = comment.string[1:].lstrip() # trim '#' and white-spaces
142-
143-
# handle pylint disable clauses
144-
disable_option_match = OPTION_PO.search(comment_text)
145-
if disable_option_match:
146-
try:
147-
values = []
148-
try:
149-
for pragma_repr in (
150-
p_rep
151-
for p_rep in parse_pragma(disable_option_match.group(2))
152-
if p_rep.action == "disable"
153-
):
154-
values.extend(pragma_repr.messages)
155-
except PragmaParserError:
156-
# Printing useful information dealing with this error is done in the lint package
157-
pass
158-
except ValueError:
159-
self.add_message(
160-
"bad-inline-option",
161-
args=disable_option_match.group(1).strip(),
162-
line=comment.start[0],
163-
)
164-
continue
165-
self.linter.add_ignored_message("fixme", line=comment.start[0])
136+
for token_info in tokens:
137+
if token_info.type != tokenize.COMMENT:
166138
continue
167-
168-
# emit warnings if necessary
169-
match = self._fixme_pattern.search("#" + comment_text.lower())
170-
if match:
139+
comment_text = token_info.string[1:].lstrip() # trim '#' and white-spaces
140+
if self._fixme_pattern.search("#" + comment_text.lower()):
171141
self.add_message(
172142
"fixme",
173-
col_offset=comment.start[1] + 1,
143+
col_offset=token_info.start[1] + 1,
174144
args=comment_text,
175-
line=comment.start[0],
145+
line=token_info.start[0],
176146
)
177147

178148

tests/functional/f/fixme.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# -*- encoding=utf-8 -*-
2-
# pylint: disable=missing-docstring, unused-variable
1+
"""Tests for fixme and its disabling and enabling."""
2+
# pylint: disable=missing-function-docstring, unused-variable
33

44
# +1: [fixme]
55
# FIXME: beep
@@ -29,5 +29,13 @@ def function():
2929

3030
#FIXME: in fact nothing to fix #pylint: disable=fixme
3131
#TODO: in fact nothing to do #pylint: disable=fixme
32-
#TODO: in fact nothing to do #pylint: disable=line-too-long, fixme
32+
#TODO: in fact nothing to do #pylint: disable=line-too-long, fixme, useless-suppression
3333
# Todoist API mentioned should not result in a message.
34+
35+
# pylint: disable-next=fixme
36+
# FIXME: Don't raise when the message is disabled
37+
38+
# This line needs to be at the end of the file to make sure it doesn't end with a comment
39+
# Pragma's compare against the 'lineno' attribute of the respective nodes which
40+
# would stop too soon otherwise.
41+
print()

tests/functional/f/fixme.rc

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
notes=XXX,TODO,./TODO
44
# Regular expression of note tags to take in consideration.
55
notes-rgx=FIXME(?!.*ISSUE-\d+)|TO.*DO
6+
enable=useless-suppression

0 commit comments

Comments
 (0)