# HG changeset patch # User Sjoerd Mullender <sjoerd@acm.org> # Date 1414768764 -3600 # Node ID 95e8189b5fb4cfb0c0364f1f5b8a009578e39ba4 # Parent 32c51a111990dceada2afeb7a9146fd9e7d80a4d Check for newline at end of file. diff -r 32c51a111990 -r 95e8189b5fb4 check_whitespace.py --- 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)