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}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index e5f28b7..5c9c88d 100755
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -1068,6 +1068,8 @@
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))
results.extend(
@@ -1322,6 +1324,20 @@
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.