changeset 6:95e8189b5fb4

Check for newline at end of file.
author Sjoerd Mullender <sjoerd@acm.org>
date Fri, 31 Oct 2014 16:19:24 +0100 (2014-10-31)
parents 32c51a111990
children 2ac85cc1e11b
files check_whitespace.py
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/check_whitespace.py	Wed Sep 11 18:56:09 2013 +0200
+++ b/check_whitespace.py	Fri Oct 31 16:19:24 2014 +0100
@@ -27,6 +27,7 @@
     wsre = re.compile(r'\+.*[ \t]$')
     tbre = re.compile(r'\+.*\t')
     resre = re.compile(r'\+(<<<<<<<|>>>>>>>)')
+    adding = False
 
     for chunk in difflines:
         for line in chunk.split('\n'):
@@ -40,6 +41,7 @@
                 continue
             if line.startswith('diff '):
                 header = True
+                adding = False
                 continue
             # hunk header - save the line number
             m = lnre.match(line)
@@ -48,6 +50,13 @@
                 continue
             if header or not filename:
                 continue
+            if line[:1] == '+':
+                adding = True
+            elif line[:1] in (' ', '-'):
+                adding = False
+            elif adding and line.startswith(r'\ No newline at end of file'):
+                adding = False
+                yield filename, linenum, 'no newline at end of file'
             # hunk body - check for an added line with bad whitespace
             if filename[-3:] == '.py' or filename[-5:] == '.py.in':
                 m = tbre.match(line)