* [contrib, committed] check_GNU_style_lib.py: Fix trailing whitespace check
@ 2017-05-29 7:50 Tom de Vries
0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2017-05-29 7:50 UTC (permalink / raw)
To: Martin Liška; +Cc: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 317 bytes --]
Hi,
this patch fixes the trailing whitespace check in check_GNU_style_lib.py.
Atm, the lines passed to the checks contain the eol char, so the
trailing whitespace regexp '(\s+)$' matches for a line '123\n', which is
in fact without trailing whitespace.
Fixed by removing the eol char.
Committed.
Thanks,
- Tom
[-- Attachment #2: 0003-check_GNU_style_lib.py-Fix-trailing-whitespace-check.patch --]
[-- Type: text/x-patch, Size: 2198 bytes --]
check_GNU_style_lib.py: Fix trailing whitespace check
2017-05-28 Tom de Vries <tom@codesourcery.com>
* check_GNU_style_lib.py (TrailingWhitespaceCheck.check): Assert no
trailing eol.
(TrailingWhitespaceTest): New unit test.
(check_GNU_style_file): Remove eol before checking.
---
contrib/check_GNU_style_lib.py | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/contrib/check_GNU_style_lib.py b/contrib/check_GNU_style_lib.py
index e1031df..63d0538 100755
--- a/contrib/check_GNU_style_lib.py
+++ b/contrib/check_GNU_style_lib.py
@@ -104,6 +104,7 @@ class TrailingWhitespaceCheck:
self.re = re.compile('(\s+)$')
def check(self, filename, lineno, line):
+ assert(len(line) == 0 or line[-1] != '\n')
m = self.re.search(line)
if m != None:
return CheckError(filename, lineno,
@@ -223,6 +224,18 @@ class LineLengthTest(unittest.TestCase):
self.assertEqual(r.console_error,
self.check.limit * 'a' + error_string(' = 123;'))
+class TrailingWhitespaceTest(unittest.TestCase):
+ def setUp(self):
+ self.check = TrailingWhitespaceCheck()
+
+ def test_trailing_whitespace_check_basic(self):
+ r = self.check.check('foo', 123, 'a = 123;')
+ self.assertIsNone(r)
+ r = self.check.check('foo', 123, 'a = 123; ')
+ self.assertIsNotNone(r)
+ r = self.check.check('foo', 123, 'a = 123;\t')
+ self.assertIsNotNone(r)
+
def check_GNU_style_file(file, file_encoding, format):
checks = [LineLengthCheck(), SpacesCheck(), TrailingWhitespaceCheck(),
SentenceSeparatorCheck(), SentenceEndOfCommentCheck(),
@@ -244,7 +257,8 @@ def check_GNU_style_file(file, file_encoding, format):
for line in hunk:
if line.is_added and line.target_line_no != None:
for check in checks:
- e = check.check(t, line.target_line_no, line.value)
+ line_chomp = line.value.replace('\n', '')
+ e = check.check(t, line.target_line_no, line_chomp)
if e != None:
errors.append(e)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-05-29 7:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-29 7:50 [contrib, committed] check_GNU_style_lib.py: Fix trailing whitespace check Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).