Adding a presubmit check for .proto files EOF newline
We want to ensure that all the .proto files in WebRTC are terminated with a newline. NOTRY= True Bug: webrtc:7904 Change-Id: Ifbea958bd449e24101049c971c463e4ccec7b90d Reviewed-on: https://chromium-review.googlesource.com/555150 Reviewed-by: Henrik Kjellander <kjellander@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#18835}
This commit is contained in:
parent
f1e34832b8
commit
960fd5b903
16
PRESUBMIT.py
16
PRESUBMIT.py
@ -577,6 +577,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))
|
||||
results.extend(_CheckNewLineAtTheEndOfProtoFiles(input_api, output_api))
|
||||
return results
|
||||
|
||||
|
||||
@ -632,3 +633,18 @@ def _CheckOrphanHeaders(input_api, output_api):
|
||||
results.append(output_api.PresubmitError(error_msg.format(
|
||||
file_path, gn_file_path)))
|
||||
return results
|
||||
|
||||
|
||||
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 = []
|
||||
source_file_filter = lambda x: input_api.FilterSourceFile(
|
||||
x, white_list=(r'.+\.proto$',))
|
||||
for f in input_api.AffectedSourceFiles(source_file_filter):
|
||||
file_path = f.LocalPath()
|
||||
with open(file_path) as f:
|
||||
lines = f.readlines()
|
||||
if lines[-1] != '\n' or lines[-2] == '\n':
|
||||
results.append(output_api.PresubmitError(error_msg.format(file_path)))
|
||||
return results
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user