Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Unified Diff: PRESUBMIT.py

Issue 43017: Add end of file newline checks to PRESUBMIT.py. (Closed)
Patch Set: Only check for \n if the file isn't empty. Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | PRESUBMIT_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT.py
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 1b33adf8ecaaa24a2b428ebc0911f80f0df517d4..7a76b0e3f590adc7287e76c9168a3c48d854e7f8 100755
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -60,10 +60,12 @@ def LocalChecks(input_api, output_api, max_cols=80):
- contains a TAB
- has a line that ends with whitespace
- contains a line >|max_cols| cols unless |max_cols| is 0.
+ - File does not end in a newline, or ends in more than one.
Note that the whole file is checked, not only the changes.
"""
cr_files = []
+ eof_files = []
results = []
excluded_paths = [input_api.re.compile(x) for x in EXCLUDED_PATHS]
files = input_api.AffectedFiles()
@@ -88,6 +90,10 @@ def LocalChecks(input_api, output_api, max_cols=80):
if '\r' in contents:
cr_files.append(path)
+ # Check that the file ends in one and only one newline character.
+ if len(contents) > 0 and (contents[-1:] != "\n" or contents[-2:-1] == "\n"):
+ eof_files.append(path)
+
local_errors = []
# Remove EOL character.
lines = contents.splitlines()
@@ -118,4 +124,8 @@ def LocalChecks(input_api, output_api, max_cols=80):
results.append(output_api.PresubmitError(
'Found CR (or CRLF) line ending in these files, please use only LF:',
items=cr_files))
+ if eof_files:
+ results.append(output_api.PresubmitError(
+ 'These files should end one (and only one) newline character:',
+ items=eof_files))
return results
« no previous file with comments | « no previous file | PRESUBMIT_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698