Эх сурвалжийг харах

allow comment lines in inclusive_language_presubmit_exempt_dirs.txt

inclusive_language_presubmit_exempt_dirs.txt is a list of
paths to exclude from the inclusive word presubmit check.
https://source.chromium.org/chromium/chromium/tools/depot_tools/+/main:presubmit_canned_checks.py;l=2602;drc=0bc7c4832e4f2d453e4826c9a2e1197e11bd6ec7

This CL allows comment lines, starting with \#, in the file.
(Also, fixes a bug to allow an empty line)

Bug: 369701326
Change-Id: I7647459281f7921362aa4070c26671f321b7cfea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5906016
Auto-Submit: Scott Lee <ddoman@chromium.org>
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Scott Lee 10 сар өмнө
parent
commit
17a0d843c1

+ 13 - 3
presubmit_canned_checks.py

@@ -2632,9 +2632,19 @@ def CheckInclusiveLanguage(input_api,
     f = input_api.ReadFile(dirs_file_path)
 
     for line in f.splitlines():
-        path = line.split()[0]
-        if len(path) > 0:
-            excluded_paths.append(path)
+        words = line.split()
+        # if a line starts with #, followed by a whitespace or line-end,
+        # it's a comment line.
+        if len(words) == 0 or words[0] == '#' or words[0] == '':
+            continue
+
+        # The first word in each line is a path.
+        # Some exempt_dirs.txt files may have additional words in each line
+        # (e.g., "third_party 1 2")
+        #
+        ## The additional words are present in legacy files for historical
+        # reasons only. DO NOT parse or require these additional words.
+        excluded_paths.append(words[0])
 
     excluded_paths = set(excluded_paths)
     for f in input_api.AffectedFiles():

+ 34 - 0
tests/presubmit_canned_checks_test.py

@@ -298,6 +298,40 @@ class InclusiveLanguageCheckTest(unittest.TestCase):
             input_api, MockOutputApi())
         self.assertEqual([], errors)
 
+    def testDirExemptWithComment(self):
+        input_api = MockInputApi()
+        input_api.change.RepositoryRoot = lambda: ''
+        input_api.presubmit_local_path = ''
+
+        input_api.files = [
+            MockFile(
+                os.path.normpath(
+                    'infra/inclusive_language_presubmit_exempt_dirs.txt'), [
+                        '# this is a comment',
+                        'dir1',
+                        '# dir2',
+                    ]),
+
+            # this should be excluded
+            MockFile(
+                os.path.normpath('dir1/1.py'),
+                [
+                    'TEST(SomeClassTest, SomeInteraction, blacklist) {',  # nocheck
+                    '}'
+                ]),
+
+            # this should not be excluded
+            MockFile(os.path.normpath('dir2/2.py'),
+                     ['- (void)testSth { V(whitelist); }']),  # nocheck
+        ]
+
+        errors = presubmit_canned_checks.CheckInclusiveLanguage(
+            input_api, MockOutputApi())
+        self.assertEqual(1, len(errors))
+        self.assertTrue(os.path.normpath('dir1/1.py') not in errors[0].message)
+        self.assertTrue(os.path.normpath('dir2/2.py') in errors[0].message)
+
+
 
 class DescriptionChecksTest(unittest.TestCase):
     def testCheckDescriptionUsesColonInsteadOfEquals(self):