2022-04-06 19:37:27 +00:00
|
|
|
# Copyright 2022 The Dawn & Tint Authors
|
2018-08-27 08:10:28 +00:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2020-11-16 15:01:27 +00:00
|
|
|
import re
|
2018-08-27 08:10:28 +00:00
|
|
|
|
2021-07-20 17:57:20 +00:00
|
|
|
USE_PYTHON3 = True
|
|
|
|
|
2022-04-06 19:37:27 +00:00
|
|
|
NONINCLUSIVE_REGEXES = [
|
2020-11-16 15:01:27 +00:00
|
|
|
r"(?i)black[-_]?list",
|
|
|
|
r"(?i)white[-_]?list",
|
|
|
|
r"(?i)gr[ea]y[-_]?list",
|
|
|
|
r"(?i)(first class citizen)",
|
|
|
|
r"(?i)black[-_]?hat",
|
|
|
|
r"(?i)white[-_]?hat",
|
|
|
|
r"(?i)gr[ea]y[-_]?hat",
|
|
|
|
r"(?i)master",
|
|
|
|
r"(?i)slave",
|
|
|
|
r"(?i)\bhim\b",
|
|
|
|
r"(?i)\bhis\b",
|
|
|
|
r"(?i)\bshe\b",
|
|
|
|
r"(?i)\bher\b",
|
|
|
|
r"(?i)\bguys\b",
|
|
|
|
r"(?i)\bhers\b",
|
|
|
|
r"(?i)\bman\b",
|
|
|
|
r"(?i)\bwoman\b",
|
|
|
|
r"(?i)\she\s",
|
|
|
|
r"(?i)\she$",
|
|
|
|
r"(?i)^he\s",
|
|
|
|
r"(?i)^he$",
|
|
|
|
r"(?i)\she['|\u2019]d\s",
|
|
|
|
r"(?i)\she['|\u2019]d$",
|
|
|
|
r"(?i)^he['|\u2019]d\s",
|
|
|
|
r"(?i)^he['|\u2019]d$",
|
|
|
|
r"(?i)\she['|\u2019]s\s",
|
|
|
|
r"(?i)\she['|\u2019]s$",
|
|
|
|
r"(?i)^he['|\u2019]s\s",
|
|
|
|
r"(?i)^he['|\u2019]s$",
|
|
|
|
r"(?i)\she['|\u2019]ll\s",
|
|
|
|
r"(?i)\she['|\u2019]ll$",
|
|
|
|
r"(?i)^he['|\u2019]ll\s",
|
|
|
|
r"(?i)^he['|\u2019]ll$",
|
|
|
|
r"(?i)grandfather",
|
|
|
|
r"(?i)\bmitm\b",
|
|
|
|
r"(?i)\bcrazy\b",
|
|
|
|
r"(?i)\binsane\b",
|
|
|
|
r"(?i)\bblind\sto\b",
|
|
|
|
r"(?i)\bflying\sblind\b",
|
|
|
|
r"(?i)\bblind\seye\b",
|
|
|
|
r"(?i)\bcripple\b",
|
|
|
|
r"(?i)\bcrippled\b",
|
|
|
|
r"(?i)\bdumb\b",
|
|
|
|
r"(?i)\bdummy\b",
|
|
|
|
r"(?i)\bparanoid\b",
|
|
|
|
r"(?i)\bsane\b",
|
|
|
|
r"(?i)\bsanity\b",
|
|
|
|
r"(?i)red[-_]?line",
|
|
|
|
]
|
|
|
|
|
2022-04-06 19:37:27 +00:00
|
|
|
NONINCLUSIVE_REGEX_LIST = []
|
|
|
|
for reg in NONINCLUSIVE_REGEXES:
|
|
|
|
NONINCLUSIVE_REGEX_LIST.append(re.compile(reg))
|
|
|
|
|
2020-11-16 15:01:27 +00:00
|
|
|
|
2022-04-06 19:37:27 +00:00
|
|
|
def _CheckNonInclusiveLanguage(input_api, output_api, source_file_filter=None):
|
2021-07-20 17:16:31 +00:00
|
|
|
"""Checks the files for non-inclusive language."""
|
2020-11-16 15:01:27 +00:00
|
|
|
|
2021-07-20 17:16:31 +00:00
|
|
|
matches = []
|
|
|
|
for f in input_api.AffectedFiles(include_deletes=False,
|
|
|
|
file_filter=source_file_filter):
|
|
|
|
for line_num, line in f.ChangedContents():
|
2022-04-06 19:37:27 +00:00
|
|
|
for reg in NONINCLUSIVE_REGEX_LIST:
|
2021-07-20 17:16:31 +00:00
|
|
|
match = reg.search(line)
|
|
|
|
if match:
|
|
|
|
matches.append(
|
|
|
|
"{} ({}): found non-inclusive language: {}".format(
|
|
|
|
f.LocalPath(), line_num, match.group(0)))
|
2020-11-16 15:01:27 +00:00
|
|
|
|
2021-07-20 17:16:31 +00:00
|
|
|
if len(matches):
|
|
|
|
return [
|
|
|
|
output_api.PresubmitPromptWarning('Non-inclusive language found:',
|
|
|
|
items=matches)
|
|
|
|
]
|
2020-11-16 15:01:27 +00:00
|
|
|
|
2021-07-20 17:16:31 +00:00
|
|
|
return []
|
2020-11-16 15:01:27 +00:00
|
|
|
|
|
|
|
|
2022-04-06 19:37:27 +00:00
|
|
|
def _NonInclusiveFileFilter(file):
|
|
|
|
filter_list = [
|
|
|
|
"PRESUBMIT.py", # Non-inclusive language check data
|
|
|
|
"docs/tint/spirv-input-output-variables.md", # External URL
|
|
|
|
"test/tint/samples/compute_boids.wgsl ", # External URL
|
|
|
|
]
|
|
|
|
return file in filter_list
|
2022-02-17 15:03:19 +00:00
|
|
|
|
2020-07-15 19:51:17 +00:00
|
|
|
|
2018-08-27 08:10:28 +00:00
|
|
|
def _DoCommonChecks(input_api, output_api):
|
|
|
|
results = []
|
2020-07-15 19:51:17 +00:00
|
|
|
results.extend(
|
|
|
|
input_api.canned_checks.CheckChangedLUCIConfigs(input_api, output_api))
|
|
|
|
results.extend(
|
2020-07-15 20:47:57 +00:00
|
|
|
input_api.canned_checks.CheckPatchFormatted(input_api,
|
|
|
|
output_api,
|
|
|
|
check_python=True))
|
2022-04-06 19:37:27 +00:00
|
|
|
results.extend(
|
|
|
|
input_api.canned_checks.CheckChangeHasDescription(
|
|
|
|
input_api, output_api))
|
|
|
|
results.extend(
|
|
|
|
input_api.canned_checks.CheckGNFormatted(input_api, output_api))
|
|
|
|
results.extend(
|
|
|
|
input_api.canned_checks.CheckChangeHasNoCrAndHasOnlyOneEol(
|
|
|
|
input_api, output_api))
|
|
|
|
results.extend(
|
|
|
|
input_api.canned_checks.CheckChangeHasNoTabs(input_api, output_api))
|
|
|
|
results.extend(
|
|
|
|
input_api.canned_checks.CheckChangeTodoHasOwner(input_api, output_api))
|
|
|
|
results.extend(
|
|
|
|
input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
|
|
|
|
input_api, output_api))
|
|
|
|
results.extend(
|
|
|
|
input_api.canned_checks.CheckDoNotSubmit(input_api, output_api))
|
2022-04-07 11:36:06 +00:00
|
|
|
# TODO(dawn:1339): Add back CheckChangeLintsClean, it fails on all Dawn
|
|
|
|
# source files because they where never linted (and use different rules).
|
2022-04-06 19:37:27 +00:00
|
|
|
results.extend(
|
|
|
|
_CheckNonInclusiveLanguage(input_api, output_api,
|
|
|
|
_NonInclusiveFileFilter))
|
2018-08-27 08:10:28 +00:00
|
|
|
return results
|
2018-08-20 12:54:15 +00:00
|
|
|
|
2020-07-15 19:51:17 +00:00
|
|
|
|
2018-08-20 12:54:15 +00:00
|
|
|
def CheckChangeOnUpload(input_api, output_api):
|
2018-08-27 08:10:28 +00:00
|
|
|
return _DoCommonChecks(input_api, output_api)
|
2018-08-20 12:54:15 +00:00
|
|
|
|
2020-07-15 19:51:17 +00:00
|
|
|
|
2018-08-20 12:54:15 +00:00
|
|
|
def CheckChangeOnCommit(input_api, output_api):
|
2018-08-27 08:10:28 +00:00
|
|
|
return _DoCommonChecks(input_api, output_api)
|