Add ban rule for anonymous namespaces in header files.

See discussion at
https://groups.google.com/a/chromium.org/g/chromium-dev/c/qgUGhXjCFrs/m/QoVu31ClDQAJ

Change-Id: Ie54f9614075402dda481d4ef74fad157510042f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6197921
Reviewed-by: Daniel Cheng <[email protected]>
Commit-Queue: Erik Chen <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1411947}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 6d6c438..f9de317a 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -2127,6 +2127,19 @@
         ),
         treat_as_error=False,
     ),
+    BanRule(
+        pattern=(r'namespace {'),
+        explanation=
+        ('Anonymous namespaces are disallowed in C++ header files. See '
+         'https://google.github.io/styleguide/cppguide.html#Internal_Linkage '
+         ' for details.',
+        ),
+        treat_as_error=False,
+        excluded_paths=[
+          _THIRD_PARTY_EXCEPT_BLINK, # Don't warn in third_party folders.
+          r'^(?!.*\.h$).*$', # Exclude all files except those that end in .h
+        ],
+    ),
 )
 
 _DEPRECATED_SYNC_CONSENT_FUNCTION_WARNING = (