Chromium Code Reviews| Index: PRESUBMIT.py |
| diff --git a/PRESUBMIT.py b/PRESUBMIT.py |
| index ad723a8b231dfc079c10220c60172f5a194878e4..918f7bb746e94a56bd7a936d38e87357a176f22a 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' + |
|
tfarina
2014/12/22 12:13:57
s/windows/Windows?
Mostyn Bramley-Moore
2014/12/22 12:17:32
Done.
|
| + '\n'.join(problems))] |
| + |
| + return [] |
| + |
| + |
| def CheckChangeOnUpload(input_api, output_api): |
| results = [] |
| results.extend(_CommonChecks(input_api, output_api)) |