Index: PRESUBMIT.py |
diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
index ad723a8b231dfc079c10220c60172f5a194878e4..568b1ae7aa76a3700324dc42065d42afe4997521 100644 |
--- a/PRESUBMIT.py |
+++ b/PRESUBMIT.py |
@@ -1403,6 +1403,7 @@ def _CommonChecks(input_api, output_api): |
results.extend(_CheckParseErrors(input_api, output_api)) |
results.extend(_CheckForIPCRules(input_api, output_api)) |
results.extend(_CheckForCopyrightedCode(input_api, output_api)) |
+ results.extend(_CheckForWindowsLineEndings(input_api, output_api)) |
if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
@@ -1588,6 +1589,40 @@ def _CheckForIPCRules(input_api, output_api): |
return [] |
+def _CheckForWindowsLineEndings(input_api, output_api): |
+ """Check source code and known ascii text files for Windows style line |
+ endings. |
+ """ |
+ known_text_files = r'.*\.(txt|html|htm|mhtml|py)$' |
+ |
+ file_inclusion_pattern = ( |
+ known_text_files, |
+ r'.+%s' % _IMPLEMENTATION_EXTENSIONS |
+ ) |
+ |
+ filter = lambda f: input_api.FilterSourceFile( |
+ f, white_list=file_inclusion_pattern, black_list=None) |
+ files = [f.LocalPath() for f in |
+ input_api.AffectedSourceFiles(filter)] |
+ |
+ problems = [] |
+ |
+ for file in files: |
+ fp = open(file, 'r') |
+ for line in fp: |
+ if line.endswith('\r\n'): |
+ problems.append(file) |
+ break |
+ fp.close() |
+ |
+ if problems: |
+ return [output_api.PresubmitPromptWarning('Are you sure that you want ' |
+ 'these files to contain Windows style line endings?\n' + |
+ '\n'.join(problems))] |
+ |
+ return [] |
+ |
+ |
def CheckChangeOnUpload(input_api, output_api): |
results = [] |
results.extend(_CommonChecks(input_api, output_api)) |