Presubmit check forbidding tab characters in source files.

WebKit's Subversion repository forbids tab characters in source files.
Follow-up to:
https://chromium-review.googlesource.com/c/angle/angle/+/1954410

Bug: angleproject:3439
Change-Id: I7ab170cae6985c62ee2f163c15d2746f620fe648
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1959750
Commit-Queue: James Darpinian <jdarpinian@chromium.org>
Reviewed-by: Jonah Ryan-Davis <jonahr@google.com>
This commit is contained in:
James Darpinian 2019-12-10 17:05:37 -08:00 коммит произвёл Commit Bot
Родитель 49135f689a
Коммит 4dff995667
1 изменённых файлов: 30 добавлений и 2 удалений

Просмотреть файл

@ -13,8 +13,8 @@ import subprocess
import sys
import tempfile
# Fragment of a regular expression that matches C++ and Objective-C++ implementation files.
_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
# Fragment of a regular expression that matches C++ and Objective-C++ implementation files and headers.
_IMPLEMENTATION_AND_HEADER_EXTENSIONS = r'\.(cc|cpp|cxx|mm|h|hpp|hxx)$'
# Fragment of a regular expression that matches C++ and Objective-C++ header files.
_HEADER_EXTENSIONS = r'\.(h|hpp|hxx)$'
@ -147,8 +147,36 @@ def _CheckExportValidity(input_api, output_api):
shutil.rmtree(outdir)
def _CheckTabsInSourceFiles(input_api, output_api):
"""Forbids tab characters in source files due to a WebKit repo requirement. """
def implementation_and_headers(f):
return input_api.FilterSourceFile(
f, white_list=(r'.+%s' % _IMPLEMENTATION_AND_HEADER_EXTENSIONS,))
files_with_tabs = []
for f in input_api.AffectedSourceFiles(implementation_and_headers):
for (num, line) in f.ChangedContents():
if '\t' in line:
files_with_tabs.append(f)
break
if files_with_tabs:
return [
output_api.PresubmitError(
'Tab characters in source files.',
items=sorted(files_with_tabs),
long_text=
'Tab characters are forbidden in ANGLE source files because WebKit\'s Subversion\n'
'repository does not allow tab characters in source files.\n'
'Please remove tab characters from these files.')
]
return []
def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(_CheckTabsInSourceFiles(input_api, output_api))
results.extend(_CheckCodeGeneration(input_api, output_api))
results.extend(_CheckChangeHasBugField(input_api, output_api))
results.extend(input_api.canned_checks.CheckChangeHasDescription(input_api, output_api))