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>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 13547a4..0de387a 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -13,8 +13,8 @@
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 @@
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))