Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disabling of fixme #7144

Merged
merged 6 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/data/messages/f/fixme/bad.py
Original file line number Diff line number Diff line change
@@ -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]
Pierre-Sassoulas marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion doc/data/messages/f/fixme/details.rst

This file was deleted.

6 changes: 5 additions & 1 deletion doc/data/messages/f/fixme/good.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Release date: TBA

Closes #7003

* Fixed the disabling of ``fixme``.
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved


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
Original file line number Diff line number Diff line change
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what this code is doing well. We were ignoring fixme if there was something looking like a pylint disable comment ? 😕

i.e. pylint: disable=fixme TODO or pylint: disable=no-member TODO should not raise ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we were seeing if there is a # pylint: disable=fixme on the same line as the fixme comment. However, we have other code that does this for us and it doesn't allow using disable-next.
Just removing is fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the part where it's specific to "fixme" though, wasn't it a special case where you could add TODO in pylint disable ? (Someone too lazy to do a grep for "pylint: disable" at some point, but not lazy enough to not add TODO everywhere ?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it actually does anything other than disallow disable. PragmaParserError probably catches all other issues.

The fact that all of our enable tests work without this shows that it is completely unnecessary 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for asking but this cleanup looked too good to be true 😄 I'm just amazed at the number of time we just remove a bunch of code to fix a bug. It's been happening over and over.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

I also was quite surprised when I found this code. At first I though for some reason the fixme checker was responsible for parsing all pragma's but then I remembered that I actually refactored that code myself and made sure that it will always be PyLinter ... 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having refactored half the codebase has its perks 😄

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
12 changes: 9 additions & 3 deletions tests/functional/f/fixme.py
Original file line number Diff line number Diff line change
@@ -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,11 @@ 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
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
print()
1 change: 1 addition & 0 deletions tests/functional/f/fixme.rc
Original file line number Diff line number Diff line change
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