summaryrefslogtreecommitdiffstats
path: root/PRESUBMIT.py
diff options
context:
space:
mode:
authormostynb <mostynb@opera.com>2015-01-07 12:31:23 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-07 20:33:07 +0000
commitb639aca53effcba6978bd37c829745b6a84699cf (patch)
treed6a669e859c9029e8000978982e539542fba7cce /PRESUBMIT.py
parent21c4d643577ee408e3ba75c32698d86be769ed9c (diff)
downloadchromium_src-b639aca53effcba6978bd37c829745b6a84699cf.zip
chromium_src-b639aca53effcba6978bd37c829745b6a84699cf.tar.gz
chromium_src-b639aca53effcba6978bd37c829745b6a84699cf.tar.bz2
add a presubmit check to avoid adding files with windows line endings
BUG=420796,385395 Review URL: https://codereview.chromium.org/786953005 Cr-Commit-Position: refs/heads/master@{#310353}
Diffstat (limited to 'PRESUBMIT.py')
-rw-r--r--PRESUBMIT.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 7c0b3fb..08b98c1 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))