Enabling and fixing CheckNewlineAtTheEndOfProtoFiles
This check has been skipped during the migration from src/webrtc to
src. It was also reporting false positives. Now it should be fixed.
NOTRY=True
Bug: chromium:611808
Change-Id: Id8567dd92099e75ac35351f053829deebf28a9d1
Reviewed-on: https://webrtc-review.googlesource.com/1580
Reviewed-by: Henrik Kjellander <kjellander@webrtc.org>
Reviewed-by: Henrik Kjellander <kjellander@google.com>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#19887}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index fcac22f..37047d4 100755
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -620,9 +620,7 @@
results.extend(RunPythonTests(input_api, output_api))
results.extend(CheckUsageOfGoogleProtobufNamespace(input_api, output_api))
results.extend(CheckOrphanHeaders(input_api, output_api))
- # TODO(mbonadei): check before re-enable because it seems it is reporting
- # some false positives.
- # results.extend(CheckNewLineAtTheEndOfProtoFiles(input_api, output_api))
+ results.extend(CheckNewlineAtTheEndOfProtoFiles(input_api, output_api))
return results
@@ -681,7 +679,7 @@
return results
-def CheckNewLineAtTheEndOfProtoFiles(input_api, output_api):
+def CheckNewlineAtTheEndOfProtoFiles(input_api, output_api):
"""Checks that all .proto files are terminated with a newline."""
error_msg = 'File {} must end with exactly one newline.'
results = []
@@ -691,6 +689,6 @@
file_path = f.LocalPath()
with open(file_path) as f:
lines = f.readlines()
- if lines[-1] != '\n' or lines[-2] == '\n':
+ if len(lines) > 0 and not lines[-1].endswith('\n'):
results.append(output_api.PresubmitError(error_msg.format(file_path)))
return results