pw_presubmit: Rename banned words check Rename banned words check to inclusive language. Bug: 386 Change-Id: I0ca7c3591c1a6fca9f1dfbc6a9e373c3f1e36f07 Requires: pigweed-internal:12620 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/46501 Commit-Queue: Joe Ethier <jethier@google.com> Reviewed-by: Joe Ethier <jethier@google.com>
diff --git a/pw_presubmit/docs.rst b/pw_presubmit/docs.rst index 0458254..dce3315 100644 --- a/pw_presubmit/docs.rst +++ b/pw_presubmit/docs.rst
@@ -114,23 +114,23 @@ C/C++ headers is ``#pragma once``. This is enabled by adding ``pw_presubmit.pragma_once`` to a presubmit program. -Banned Words -============ -.. banned-words: disable +Inclusive Language +================== +.. inclusive-language: disable -The banned words check looks for words that are typical of non-inclusive code, -like using "master" and "slave" in place of "primary" and "secondary" or +The inclusive language check looks for words that are typical of non-inclusive +code, like using "master" and "slave" in place of "primary" and "secondary" or "sanity check" in place of "consistency check". -.. banned-words: enable +.. inclusive-language: enable -These checks can be disabled for individual lines with "banned-words: ignore" -on the line in question or the line above it, or for entire blocks by using -"banned-words: disable" before the block and "banned-words: enable" after the -block. +These checks can be disabled for individual lines with +"inclusive-language: ignore" on the line in question or the line above it, or +for entire blocks by using "inclusive-language: disable" before the block and +"inclusive-language: enable" after the block. .. In case things get moved around in the previous paragraphs the enable line -.. is repeated here: banned-words: enable. +.. is repeated here: inclusive-language: enable. pw_presubmit ~~~~~~~~~~~~ @@ -166,8 +166,8 @@ sys.exit(2) import pw_presubmit - from pw_presubmit import banned_words, build, cli, environment, format_code - from pw_presubmit import git_repo, python_checks, filter_paths + from pw_presubmit import build, cli, environment, format_code, git_repo + from pw_presubmit import inclusive_language, python_checks, filter_paths from pw_presubmit import PresubmitContext from pw_presubmit.install_hook import install_hook @@ -230,7 +230,7 @@ # Use the upstream formatting checks, with custom path filters applied. format_code.presubmit_checks(exclude=PATH_EXCLUSIONS), # Include the upstream inclusive language check. - banned_words.banned_words, + inclusive_language.inclusive_language, ) FULL = (
diff --git a/pw_presubmit/py/BUILD.gn b/pw_presubmit/py/BUILD.gn index 444ab0f..f49fbeb 100644 --- a/pw_presubmit/py/BUILD.gn +++ b/pw_presubmit/py/BUILD.gn
@@ -20,12 +20,12 @@ setup = [ "setup.py" ] sources = [ "pw_presubmit/__init__.py", - "pw_presubmit/banned_words.py", "pw_presubmit/build.py", "pw_presubmit/cli.py", "pw_presubmit/environment.py", "pw_presubmit/format_code.py", "pw_presubmit/git_repo.py", + "pw_presubmit/inclusive_language.py", "pw_presubmit/install_hook.py", "pw_presubmit/pigweed_presubmit.py", "pw_presubmit/presubmit.py",
diff --git a/pw_presubmit/py/pw_presubmit/banned_words.py b/pw_presubmit/py/pw_presubmit/inclusive_language.py similarity index 75% rename from pw_presubmit/py/pw_presubmit/banned_words.py rename to pw_presubmit/py/pw_presubmit/inclusive_language.py index 8c789e6..915027a 100644 --- a/pw_presubmit/py/pw_presubmit/banned_words.py +++ b/pw_presubmit/py/pw_presubmit/inclusive_language.py
@@ -11,7 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. -"""Banned words presubmit check.""" +"""Inclusive language presubmit check.""" import collections from pathlib import Path @@ -22,8 +22,8 @@ # List borrowed from Android: # https://source.android.com/setup/contribute/respectful-code -# banned-words: disable -BANNED_WORDS = [ +# inclusive-language: disable +NON_INCLUSIVE_WORDS = [ r'master', r'slave', r'(white|gr[ae]y|black)\s*(list|hat)', @@ -40,17 +40,17 @@ r'm[ae]n[-\s]*in[-\s]*the[-\s]*middle', r'mitm', ] -# banned-words: enable +# inclusive-language: enable -# Test: master # banned-words: ignore +# Test: master # inclusive-language: ignore # Test: master -def _process_banned_words(*words): - """Turn banned-words list into one big regex with common inflections.""" +def _process_inclusive_language(*words): + """Turn word list into one big regex with common inflections.""" if not words: - words = tuple(BANNED_WORDS) + words = tuple(NON_INCLUSIVE_WORDS) all_words = [] for entry in words: @@ -71,7 +71,7 @@ ) -BANNED_WORDS_REGEX = _process_banned_words() +NON_INCLUSIVE_WORDS_REGEX = _process_inclusive_language() # If seen, ignore this line and the next. _IGNORE = 'banned-words: ignore' @@ -81,9 +81,9 @@ _ENABLE = 'banned-words: enable' -def banned_words( +def inclusive_language( ctx: presubmit.PresubmitContext, - words_regex=BANNED_WORDS_REGEX, + words_regex=NON_INCLUSIVE_WORDS_REGEX, ): """Presubmit check that ensures files do not contain banned words.""" @@ -123,19 +123,29 @@ print('=' * 40) print(path) for match in matches: - print(f'Found banned word "{match.word}" on line {match.line}') + print( + f'Found non-inclusive word "{match.word}" on line {match.line}' + ) if found_words: + print() + print(""" +Individual lines can be ignored with "inclusive-language: ignore". Blocks can be +ignored with "inclusive-language: disable" and reenabled with +"inclusive-language: enable". +""".strip()) + # Re-enable just in case: banned-words: enable. + raise presubmit.PresubmitFailure -def banned_words_checker(*words): +def inclusive_language_checker(*words): """Create banned words checker for the given list of banned words.""" - regex = _process_banned_words(*words) + regex = _process_inclusive_language(*words) - def banned_words( # pylint: disable=redefined-outer-name + def inclusive_language( # pylint: disable=redefined-outer-name ctx: presubmit.PresubmitContext): - globals()['banned_words'](ctx, regex) + globals()['inclusive_language'](ctx, regex) - return banned_words + return inclusive_language
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py index d2e0040..5e0e747 100755 --- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py +++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -35,8 +35,8 @@ import pw_package.pigweed_packages -from pw_presubmit import banned_words, build, cli, format_code, git_repo -from pw_presubmit import call, filter_paths, plural, PresubmitContext +from pw_presubmit import build, cli, format_code, git_repo, call, filter_paths +from pw_presubmit import inclusive_language, plural, PresubmitContext from pw_presubmit import PresubmitFailure, Programs from pw_presubmit.install_hook import install_hook @@ -621,7 +621,7 @@ # OTHER_CHECKS = ( - banned_words.banned_words, + inclusive_language.inclusive_language, # TODO(pwbug/45): Remove clang-tidy from OTHER_CHECKS when it passes. clang_tidy, # Build that attempts to duplicate the build OSS-Fuzz does. Currently