pw_presubmit: Find more inclusive language issues Find cases where a banned word, e.g., "banned" is inside a larger identifier, like "FooBannedBar". Assuming there are initial caps in the identifier, "Banned" will be found and presented as an issue. Change-Id: Ib1b4a2e2f805cc55aeec4afb6087e4c09c4e6c68 Bug: 386 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/48563 Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com> Reviewed-by: Joe Ethier <jethier@google.com>
diff --git a/pw_presubmit/py/pw_presubmit/inclusive_language.py b/pw_presubmit/py/pw_presubmit/inclusive_language.py index a751954..087fe58 100644 --- a/pw_presubmit/py/pw_presubmit/inclusive_language.py +++ b/pw_presubmit/py/pw_presubmit/inclusive_language.py
@@ -65,10 +65,12 @@ for word in all_words: _ = re.compile(word) + word_boundary = ( + r'(\b|_|(?<=[a-z])(?=[A-Z])|(?<=[0-9])(?=\w)|(?<=\w)(?=[0-9]))') + return re.compile( - r"(\b|_)({})(\b|_|e?[sd]_?\b)".format('|'.join(all_words)), - re.IGNORECASE, - ) + r"({b})(?i:{w})(e?[sd]{b}|{b})".format(w='|'.join(all_words), + b=word_boundary), ) NON_INCLUSIVE_WORDS_REGEX = _process_inclusive_language()