mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Implement Newline Check in the Presubmit
This will prevent committing source files with CRLF newlines. Bug: None Change-Id: I43c1d9a192a445a27f75b336e9ff6e45e012866b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/335760 Auto-Submit: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41598}
This commit is contained in:
parent
25b29829dd
commit
eb76f193f3
1 changed files with 16 additions and 0 deletions
16
PRESUBMIT.py
16
PRESUBMIT.py
|
@ -1067,6 +1067,8 @@ def CommonChecks(input_api, output_api):
|
|||
results.extend(
|
||||
CheckNewlineAtTheEndOfProtoFiles(
|
||||
input_api, output_api, source_file_filter=non_third_party_sources))
|
||||
results.extend(
|
||||
CheckLFNewline(input_api, output_api, non_third_party_sources))
|
||||
results.extend(
|
||||
CheckNoStreamUsageIsAdded(input_api, output_api,
|
||||
non_third_party_sources))
|
||||
|
@ -1322,6 +1324,20 @@ def CheckNewlineAtTheEndOfProtoFiles(input_api, output_api,
|
|||
return results
|
||||
|
||||
|
||||
def CheckLFNewline(input_api, output_api, source_file_filter):
|
||||
"""Checks that all files have LF newlines."""
|
||||
error_msg = 'File {} must use LF newlines.'
|
||||
results = []
|
||||
file_filter = lambda x: input_api.FilterSourceFile(
|
||||
x, files_to_check=(r'.+', )) and source_file_filter(x)
|
||||
for f in input_api.AffectedSourceFiles(file_filter):
|
||||
file_path = f.LocalPath()
|
||||
with open(file_path, 'rb') as f:
|
||||
if b'\r\n' in f.read():
|
||||
results.append(
|
||||
output_api.PresubmitError(error_msg.format(file_path)))
|
||||
return results
|
||||
|
||||
def _ExtractAddRulesFromParsedDeps(parsed_deps):
|
||||
"""Extract the rules that add dependencies from a parsed DEPS file.
|
||||
|
||||
|
|
Loading…
Reference in a new issue