Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 1 | # Copyright 2022 The Dawn & Tint Authors |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 15 | import re |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 16 | |
Ryan Harrison | 45aed4b | 2021-07-20 17:57:20 +0000 | [diff] [blame] | 17 | USE_PYTHON3 = True |
| 18 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 19 | NONINCLUSIVE_REGEXES = [ |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 20 | r"(?i)black[-_]?list", |
| 21 | r"(?i)white[-_]?list", |
| 22 | r"(?i)gr[ea]y[-_]?list", |
| 23 | r"(?i)(first class citizen)", |
| 24 | r"(?i)black[-_]?hat", |
| 25 | r"(?i)white[-_]?hat", |
| 26 | r"(?i)gr[ea]y[-_]?hat", |
| 27 | r"(?i)master", |
| 28 | r"(?i)slave", |
| 29 | r"(?i)\bhim\b", |
| 30 | r"(?i)\bhis\b", |
| 31 | r"(?i)\bshe\b", |
| 32 | r"(?i)\bher\b", |
| 33 | r"(?i)\bguys\b", |
| 34 | r"(?i)\bhers\b", |
| 35 | r"(?i)\bman\b", |
| 36 | r"(?i)\bwoman\b", |
| 37 | r"(?i)\she\s", |
| 38 | r"(?i)\she$", |
| 39 | r"(?i)^he\s", |
| 40 | r"(?i)^he$", |
| 41 | r"(?i)\she['|\u2019]d\s", |
| 42 | r"(?i)\she['|\u2019]d$", |
| 43 | r"(?i)^he['|\u2019]d\s", |
| 44 | r"(?i)^he['|\u2019]d$", |
| 45 | r"(?i)\she['|\u2019]s\s", |
| 46 | r"(?i)\she['|\u2019]s$", |
| 47 | r"(?i)^he['|\u2019]s\s", |
| 48 | r"(?i)^he['|\u2019]s$", |
| 49 | r"(?i)\she['|\u2019]ll\s", |
| 50 | r"(?i)\she['|\u2019]ll$", |
| 51 | r"(?i)^he['|\u2019]ll\s", |
| 52 | r"(?i)^he['|\u2019]ll$", |
| 53 | r"(?i)grandfather", |
| 54 | r"(?i)\bmitm\b", |
| 55 | r"(?i)\bcrazy\b", |
| 56 | r"(?i)\binsane\b", |
| 57 | r"(?i)\bblind\sto\b", |
| 58 | r"(?i)\bflying\sblind\b", |
| 59 | r"(?i)\bblind\seye\b", |
| 60 | r"(?i)\bcripple\b", |
| 61 | r"(?i)\bcrippled\b", |
| 62 | r"(?i)\bdumb\b", |
| 63 | r"(?i)\bdummy\b", |
| 64 | r"(?i)\bparanoid\b", |
| 65 | r"(?i)\bsane\b", |
| 66 | r"(?i)\bsanity\b", |
| 67 | r"(?i)red[-_]?line", |
| 68 | ] |
| 69 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 70 | NONINCLUSIVE_REGEX_LIST = [] |
| 71 | for reg in NONINCLUSIVE_REGEXES: |
| 72 | NONINCLUSIVE_REGEX_LIST.append(re.compile(reg)) |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 73 | |
dan sinclair | fcf5679 | 2022-04-11 13:05:40 +0000 | [diff] [blame] | 74 | LINT_FILTERS = [] |
dan sinclair | c4502a0 | 2022-04-08 12:08:56 +0000 | [diff] [blame] | 75 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 76 | |
| 77 | def _CheckNonInclusiveLanguage(input_api, output_api, source_file_filter=None): |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 78 | """Checks the files for non-inclusive language.""" |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 79 | |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 80 | matches = [] |
| 81 | for f in input_api.AffectedFiles(include_deletes=False, |
| 82 | file_filter=source_file_filter): |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 83 | line_num = 0 |
| 84 | for line in f.NewContents(): |
| 85 | line_num += 1 |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 86 | for reg in NONINCLUSIVE_REGEX_LIST: |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 87 | match = reg.search(line) |
| 88 | if match: |
| 89 | matches.append( |
| 90 | "{} ({}): found non-inclusive language: {}".format( |
| 91 | f.LocalPath(), line_num, match.group(0))) |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 92 | |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 93 | if len(matches): |
| 94 | return [ |
dan sinclair | fcf5679 | 2022-04-11 13:05:40 +0000 | [diff] [blame] | 95 | output_api.PresubmitPromptWarning("Non-inclusive language found:", |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 96 | items=matches) |
| 97 | ] |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 98 | |
Ryan Harrison | 6d27f23 | 2021-07-20 17:16:31 +0000 | [diff] [blame] | 99 | return [] |
dan sinclair | d9496f3 | 2020-11-16 15:01:27 +0000 | [diff] [blame] | 100 | |
| 101 | |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 102 | def _NonInclusiveFileFilter(file): |
| 103 | filter_list = [ |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 104 | "Doxyfile", # References to main pages |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 105 | "PRESUBMIT.py", # Non-inclusive language check data |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 106 | "PRESUBMIT.py.tint", # Non-inclusive language check data |
| 107 | "docs/dawn/debug_markers.md", # External URL |
| 108 | "docs/dawn/infra.md", # Infra settings |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 109 | "docs/tint/spirv-input-output-variables.md", # External URL |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 110 | "infra/config/global/generated/cr-buildbucket.cfg", # Infra settings |
| 111 | "infra/config/global/main.star", # Infra settings |
| 112 | "infra/kokoro/windows/build.bat", # External URL |
| 113 | "src/dawn/common/GPUInfo.cpp", # External URL |
| 114 | "src/dawn/native/metal/BackendMTL.mm", # OSX Constant |
| 115 | "src/dawn/native/vulkan/SamplerVk.cpp", # External URL |
| 116 | "src/dawn/native/vulkan/TextureVk.cpp", # External URL |
| 117 | "src/dawn/node/tools/src/cmd/run-cts/main.go", # Terminal type name |
| 118 | "src/dawn/samples/ComputeBoids.cpp", # External URL |
| 119 | "src/dawn/tests/end2end/DepthBiasTests.cpp", # External URL |
dan sinclair | 46c32d8 | 2022-07-20 15:53:14 +0000 | [diff] [blame] | 120 | "src/tint/transform/canonicalize_entry_point_io.cc", # External URL |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 121 | "test/tint/samples/compute_boids.wgsl", # External URL |
| 122 | "third_party/khronos/KHR/khrplatform.h", # Third party file |
| 123 | "tools/roll-all", # Branch name |
| 124 | "tools/src/container/key.go", # External URL |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 125 | "go.sum", # External URL |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 126 | ] |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 127 | return file.LocalPath() not in filter_list |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 128 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 129 | |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 130 | def _DoCommonChecks(input_api, output_api): |
| 131 | results = [] |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 132 | results.extend( |
| 133 | input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api)) |
| 134 | results.extend( |
Kai Ninomiya | 8296112 | 2020-07-15 20:47:57 +0000 | [diff] [blame] | 135 | input_api.canned_checks.CheckPatchFormatted(input_api, |
| 136 | output_api, |
| 137 | check_python=True)) |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 138 | results.extend( |
| 139 | input_api.canned_checks.CheckChangeHasDescription( |
| 140 | input_api, output_api)) |
| 141 | results.extend( |
| 142 | input_api.canned_checks.CheckGNFormatted(input_api, output_api)) |
| 143 | results.extend( |
| 144 | input_api.canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol( |
| 145 | input_api, output_api)) |
| 146 | results.extend( |
| 147 | input_api.canned_checks.CheckChangeHasNoTabs(input_api, output_api)) |
| 148 | results.extend( |
| 149 | input_api.canned_checks.CheckChangeTodoHasOwner(input_api, output_api)) |
| 150 | results.extend( |
| 151 | input_api.canned_checks.CheckChangeHasNoStrayWhitespace( |
| 152 | input_api, output_api)) |
| 153 | results.extend( |
| 154 | input_api.canned_checks.CheckDoNotSubmit(input_api, output_api)) |
dan sinclair | 2a3d994 | 2022-04-13 16:14:26 +0000 | [diff] [blame] | 155 | # Note, the verbose_level here should match what is set in tools/lint so |
| 156 | # the same set of lint errors are reported on the CQ and Kokoro bots. |
dan sinclair | c4502a0 | 2022-04-08 12:08:56 +0000 | [diff] [blame] | 157 | results.extend( |
| 158 | input_api.canned_checks.CheckChangeLintsClean( |
dan sinclair | 2a3d994 | 2022-04-13 16:14:26 +0000 | [diff] [blame] | 159 | input_api, output_api, lint_filters=LINT_FILTERS, verbose_level=1)) |
Ryan Harrison | e87ac76 | 2022-04-06 15:37:27 -0400 | [diff] [blame] | 160 | results.extend( |
| 161 | _CheckNonInclusiveLanguage(input_api, output_api, |
| 162 | _NonInclusiveFileFilter)) |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 163 | return results |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 164 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 165 | |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 166 | def CheckChangeOnUpload(input_api, output_api): |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 167 | return _DoCommonChecks(input_api, output_api) |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 168 | |
Kai Ninomiya | 01aeca2 | 2020-07-15 19:51:17 +0000 | [diff] [blame] | 169 | |
Corentin Wallez | 99612ae | 2018-08-20 14:54:15 +0200 | [diff] [blame] | 170 | def CheckChangeOnCommit(input_api, output_api): |
Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 171 | return _DoCommonChecks(input_api, output_api) |