summaryrefslogtreecommitdiffstats
path: root/PRESUBMIT.py
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 13:55:09 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 13:55:09 +0000
commit2fcccc7295206f24e1bc8526b40273cc6c30373e (patch)
treec92ee96f5dc55c12176a4f61298f640bca11c78d /PRESUBMIT.py
parent7afa9c92e0176b35a01fc28acbe7ca110a0d8871 (diff)
downloadchromium_src-2fcccc7295206f24e1bc8526b40273cc6c30373e.zip
chromium_src-2fcccc7295206f24e1bc8526b40273cc6c30373e.tar.gz
chromium_src-2fcccc7295206f24e1bc8526b40273cc6c30373e.tar.bz2
Add end of file newline checks to PRESUBMIT.py.
This makes sure that: - Files end in a newline character, this is otherwise a fatal error with GCC. - Files end in only one newline character, and not a bunch of whitespace. Review URL: http://codereview.chromium.org/43017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11330 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'PRESUBMIT.py')
-rwxr-xr-xPRESUBMIT.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 1b33adf..6809548 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 in one (and only one) newline character:',
+ items=eof_files))
return results