diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | pylint/checkers/format.py | 13 | ||||
-rw-r--r-- | pylint/message/message_handler_mix_in.py | 2 | ||||
-rw-r--r-- | tests/functional/u/useless/useless_suppression.py | 12 |
4 files changed, 22 insertions, 9 deletions
@@ -47,6 +47,10 @@ Release date: TBA Closes #5066 +* Fix false-positive ``useless-suppression`` for ``line-too-long`` + + Closes #4212 + * Fixed ``invalid-name`` not checking parameters of overwritten base ``object`` methods Closes #3614 diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py index e0d627e1c..7817dba72 100644 --- a/pylint/checkers/format.py +++ b/pylint/checkers/format.py @@ -673,7 +673,7 @@ class FormatChecker(BaseTokenChecker): "trailing-whitespace", line=i, col_offset=len(stripped_line) ) - def check_line_length(self, line: str, i: int) -> None: + def check_line_length(self, line: str, i: int, checker_off: bool) -> None: """ Check that the line length is less than the authorized value """ @@ -681,7 +681,10 @@ class FormatChecker(BaseTokenChecker): ignore_long_line = self.config.ignore_long_lines line = line.rstrip() if len(line) > max_chars and not ignore_long_line.search(line): - self.add_message("line-too-long", line=i, args=(len(line), max_chars)) + if checker_off: + self.linter.add_ignored_message("line-too-long", i) + else: + self.add_message("line-too-long", line=i, args=(len(line), max_chars)) @staticmethod def remove_pylint_option_from_lines(options_pattern_obj) -> str: @@ -775,16 +778,16 @@ class FormatChecker(BaseTokenChecker): # Line length check may be deactivated through `pylint: disable` comment mobj = OPTION_PO.search(lines) + checker_off = False if mobj: if not self.is_line_length_check_activated(mobj): - # the line length check is deactivated, we can stop here - return + checker_off = True # The 'pylint: disable whatever' should not be taken into account for line length count lines = self.remove_pylint_option_from_lines(mobj) # here we re-run specific_splitlines since we have filtered out pylint options above for offset, line in enumerate(self.specific_splitlines(lines)): - self.check_line_length(line, lineno + offset) + self.check_line_length(line, lineno + offset, checker_off) def check_indent_level(self, string, expected, line_num): """return the indent level of the string""" diff --git a/pylint/message/message_handler_mix_in.py b/pylint/message/message_handler_mix_in.py index 185658d4a..662a086cb 100644 --- a/pylint/message/message_handler_mix_in.py +++ b/pylint/message/message_handler_mix_in.py @@ -261,7 +261,7 @@ class MessagesHandlerMixIn: self: "PyLinter", msgid: str, line: int, - node: nodes.NodeNG, + node: Optional[nodes.NodeNG] = None, confidence: Optional[Confidence] = UNDEFINED, ) -> None: """Prepares a message to be added to the ignored message storage diff --git a/tests/functional/u/useless/useless_suppression.py b/tests/functional/u/useless/useless_suppression.py index f9bf7d490..7ca3f74ce 100644 --- a/tests/functional/u/useless/useless_suppression.py +++ b/tests/functional/u/useless/useless_suppression.py @@ -1,6 +1,12 @@ -"""Test for useless suppression false positive for wrong-import-order -Reported in https://github.com/PyCQA/pylint/issues/2366""" -# pylint: enable=useless-suppression +"""Tests for useless suppressions""" +# pylint: enable=useless-suppression, line-too-long # pylint: disable=unused-import, wrong-import-order + +# False positive for wrong-import-order +# Reported in https://github.com/PyCQA/pylint/issues/2366 from pylint import run_pylint import astroid + +# False-positive for 'line-too-long' +# Reported in https://github.com/PyCQA/pylint/issues/4212 +VAR = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" # pylint: disable=line-too-long |