diff options
author | vinnyrose <vinnyrose@users.noreply.github.com> | 2017-04-13 04:49:15 -0400 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2017-04-13 11:49:15 +0300 |
commit | 67b1508d91ae2983aa9b6c2ead374a6cb5ff3e3e (patch) | |
tree | 6e074a14b850241214e63ff5736c960d6f1dbfa3 /pylint | |
parent | 3ccda499db433200e783d5be76004930817efe47 (diff) | |
download | pylint-git-67b1508d91ae2983aa9b6c2ead374a6cb5ff3e3e.tar.gz |
Don't emit missing-final-newline or trailing-whitespace for formfeeds. (#1283)
Don't emit missing-final-newline or trailing-whitespace for formfeeds.
Keep the builtin str.splitlines but check for the superset characters and recombine them later.
Close #1218.
Close #1219
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/checkers/format.py | 25 | ||||
-rw-r--r-- | pylint/test/unittest_checker_format.py | 21 |
2 files changed, 41 insertions, 5 deletions
diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py index b3febe12e..1c5b0e93a 100644 --- a/pylint/checkers/format.py +++ b/pylint/checkers/format.py @@ -984,11 +984,12 @@ class FormatChecker(BaseTokenChecker): max_chars = self.config.max_line_length ignore_long_line = self.config.ignore_long_lines - for line in lines.splitlines(True): + def check_line(line, i): if not line.endswith('\n'): self.add_message('missing-final-newline', line=i) else: - stripped_line = line.rstrip() + # 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 @@ -1002,7 +1003,25 @@ class FormatChecker(BaseTokenChecker): 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)) - i += 1 + return i + 1 + + unsplit_ends = { + '\v', '\x0b', '\f', '\x0c', '\x1c', '\x1d', '\x1e', '\x85', '\u2028', '\u2029'} + unsplit = [] + for line in lines.splitlines(True): + if line[-1] in unsplit_ends: + unsplit.append(line) + continue + + if unsplit: + unsplit.append(line) + line = ''.join(unsplit) + unsplit = [] + + i = check_line(line, i) + + if unsplit: + check_line(''.join(unsplit), i) def check_indent_level(self, string, expected, line_num): """return the indent level of the string diff --git a/pylint/test/unittest_checker_format.py b/pylint/test/unittest_checker_format.py index 404401ffa..7820c561f 100644 --- a/pylint/test/unittest_checker_format.py +++ b/pylint/test/unittest_checker_format.py @@ -300,8 +300,25 @@ class TestCheckSpace(CheckerTestCase): 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')) + 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')) + 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')) |