From 0a7a4d4aadcf409be9a3dfb5b60fd6297034a5d2 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sun, 3 May 2020 10:00:28 +0200 Subject: [PATCH] Remove the space_check option and its code --- ChangeLog | 3 +++ doc/whatsnew/2.6.rst | 4 ++- pylint/checkers/format.py | 42 ++++++------------------------- tests/checkers/unittest_format.py | 24 ------------------ 4 files changed, 13 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14d4c057a8..d9a20be99b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,9 @@ Release date: TBA Close #246, #289, #638, #747, #1148, #1179, #1943, #2041, #2301, #2304, #2944, #3565 +* The no-space-check option has been removed. It's no longer possible to consider empty line like a `trailing-whitespace` by using clever options + +Close #1368 What's New in Pylint 2.5.1? =========================== diff --git a/doc/whatsnew/2.6.rst b/doc/whatsnew/2.6.rst index 6d68287184..10f6f455f6 100644 --- a/doc/whatsnew/2.6.rst +++ b/doc/whatsnew/2.6.rst @@ -16,4 +16,6 @@ New checkers Other Changes ============= -* `bad-continuation` and `bad-whitespace` have been removed, `black` or another formatter can help you with this better than Pylint +* `bad-continuation` and `bad-whitespace` have been removed. `black` or another formatter can help you with this better than Pylint + +* The `no-space-check` option has been removed, it's no longer possible to consider empty line like a `trailing-whitespace` by using clever options. diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py index 2f8048c6da..af35bd1a93 100644 --- a/pylint/checkers/format.py +++ b/pylint/checkers/format.py @@ -117,13 +117,6 @@ _MUST_NOT = 1 _IGNORE = 2 -# Whitespace checking config constants -_DICT_SEPARATOR = "dict-separator" -_TRAILING_COMMA = "trailing-comma" -_EMPTY_LINE = "empty-line" -_NO_SPACE_CHECK_CHOICES = [_TRAILING_COMMA, _DICT_SEPARATOR, _EMPTY_LINE] -_DEFAULT_NO_SPACE_CHECK_CHOICES = [_TRAILING_COMMA, _DICT_SEPARATOR] - MSGS = { "C0301": ( "Line too long (%s/%s)", @@ -301,24 +294,6 @@ class FormatChecker(BaseTokenChecker): ), }, ), - ( - "no-space-check", - { - "default": ",".join(_DEFAULT_NO_SPACE_CHECK_CHOICES), - "metavar": ",".join(_NO_SPACE_CHECK_CHOICES), - "type": "multiple_choice", - "choices": _NO_SPACE_CHECK_CHOICES, - "help": ( - "List of optional constructs for which whitespace " - "checking is disabled. " - "`" + _DICT_SEPARATOR + "` is used to allow tabulation " - "in dicts, etc.: {1 : 1,\\n222: 2}. " - "`" + _TRAILING_COMMA + "` allows a space between comma " - "and closing bracket: (a, ). " - "`" + _EMPTY_LINE + "` allows space-only lines." - ), - }, - ), ( "max-module-lines", { @@ -662,16 +637,13 @@ def check_line_ending(self, line: str, i: int) -> None: """ if not line.endswith("\n"): self.add_message("missing-final-newline", line=i) - else: - # exclude \f (formfeed) from the rstrip - stripped_line = line.rstrip("\t\n\r\v ") - if not stripped_line and _EMPTY_LINE in self.config.no_space_check: - # allow empty lines - pass - elif line[len(stripped_line) :] not in ("\n", "\r\n"): - self.add_message( - "trailing-whitespace", line=i, col_offset=len(stripped_line) - ) + return + # exclude \f (formfeed) from the rstrip + stripped_line = line.rstrip("\t\n\r\v ") + if line[len(stripped_line) :] not in ("\n", "\r\n"): + self.add_message( + "trailing-whitespace", line=i, col_offset=len(stripped_line) + ) def check_line_length(self, line: str, i: int) -> None: """ diff --git a/tests/checkers/unittest_format.py b/tests/checkers/unittest_format.py index 5009279f70..75b0c79674 100644 --- a/tests/checkers/unittest_format.py +++ b/tests/checkers/unittest_format.py @@ -214,30 +214,6 @@ def testKeywordParensFalsePositive(self): class TestCheckSpace(CheckerTestCase): CHECKER_CLASS = FormatChecker - def testEmptyLines(self): - self.checker.config.no_space_check = [] - with self.assertAddsMessages(Message("trailing-whitespace", line=2)): - self.checker.process_tokens(_tokenize_str("a = 1\n \nb = 2\n")) - - with self.assertAddsMessages(Message("trailing-whitespace", line=2)): - self.checker.process_tokens(_tokenize_str("a = 1\n\t\nb = 2\n")) - - with self.assertAddsMessages(Message("trailing-whitespace", line=2)): - self.checker.process_tokens(_tokenize_str("a = 1\n\v\nb = 2\n")) - - with self.assertNoMessages(): - self.checker.process_tokens(_tokenize_str("a = 1\n\f\nb = 2\n")) - - self.checker.config.no_space_check = ["empty-line"] - with self.assertNoMessages(): - self.checker.process_tokens(_tokenize_str("a = 1\n \nb = 2\n")) - - with self.assertNoMessages(): - self.checker.process_tokens(_tokenize_str("a = 1\n\t\nb = 2\n")) - - with self.assertNoMessages(): - self.checker.process_tokens(_tokenize_str("a = 1\n\v\nb = 2\n")) - def test_encoding_token(self): """Make sure the encoding token doesn't change the checker's behavior