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}
This commit is contained in:
Mirko Bonadei
2017-09-18 11:33:13 +02:00
committed by Commit Bot
parent cb728ea83a
commit a730c1c5ae
3 changed files with 75 additions and 6 deletions

View File

@ -620,9 +620,7 @@ def CommonChecks(input_api, output_api):
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 @@ def CheckOrphanHeaders(input_api, output_api):
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 @@ def CheckNewLineAtTheEndOfProtoFiles(input_api, output_api):
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