Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Unified Diff: PRESUBMIT.py

Issue 786953005: add a presubmit check to avoid adding files with windows line endings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/windows/Windows/ Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698