Skip to contentSkip to conversation

devtools: add script to check for non inclusive naming

PATCH Superseded Stephen Hemminger 2 participants 6 messages Mar 31, 2023 – Apr 5, 2023

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devtools: add script to check for non inclusive naming

Shell script to find use of words that not be used. By default it prints matches. The -q (quiet) option is used to just count. There is also -l option which lists lines matching (like grep -l).

Examples:

 $ ./devtools/check-naming.sh -q
Total files: 37 errors, 90 warnings, 1 suggestions
 $ ./devtools/check-naming.sh -q -l
Total lines: 121 errors, 255 warnings, 1 suggestions

Uses the word lists from Inclusive Naming Initiative see https://inclusivenaming.org/word-lists/

---
 devtools/check-naming.sh  | 89 +++++++++++++++++++++++++++++++++++++++
 devtools/naming/tier1.txt |  8 ++++
 devtools/naming/tier2.txt |  1 +
 devtools/naming/tier3.txt |  3 ++
 4 files changed, 101 insertions(+)
 create mode 100755 devtools/check-naming.sh
 create mode 100644 devtools/naming/tier1.txt
 create mode 100644 devtools/naming/tier2.txt
 create mode 100644 devtools/naming/tier3.txt
devtools/check-naming.sh new file +89 -0
new file mode 100755
index 000000000000..2a25eaa2eef9
@@ -0,0 +1,89 @@
+#! /bin/bash
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Produce a list of files with non-inclusive naming
+
+errors=0
+warnings=0
+suggestions=0
+quiet=false
+veborse=false
+lines='-l'
+
+print_usage () {
+    echo "usage: $(basename $0) [-l] [-q] [-v]"
+    exit 1
+}
+
+# Locate word list files
+selfdir=$(dirname $(readlink -f $0))
+words=$selfdir/naming
+
+# These give false positives
+skipfiles=( ':^devtools/naming/' \
+	    ':^doc/guides/rel_notes/' \
+	    ':^doc/guides/contributing/coding_style.rst' \
+	    ':^doc/guides/prog_guide/glossary.rst' \
+)
+# These are obsolete
+skipfiles+=( \
+	    ':^drivers/net/liquidio/' \
+	    ':^drivers/net/bnx2x/' \
+	    ':^lib/table/' \
+	    ':^lib/port/' \
+	    ':^lib/pipeline/' \
+	    ':^examples/pipeline/' \
+)
+
+#
+# check_wordlist wordfile description
+check_wordlist() {
+    local list=$words/$1
+    local description=$2
+
+    git grep -i $lines -f $list -- ${skipfiles[@]} > $tmpfile
+    count=$(wc -l < $tmpfile)
+    if ! $quiet; then
+	if [ $count -gt 0 ]; then
+	    if $verbose; then
+   		    echo $description
+		    echo $description | tr '[:print:]' '-'
+	    fi
+   	    cat $tmpfile
+	    echo
+	fi
+    fi
+    return $count
+}
+
+while getopts lqvh ARG ; do
+	case $ARG in
+		l ) lines= ;;
+		q ) quiet=true ;;
+		v ) verbose=true ;;
+		h ) print_usage ; exit 0 ;;
+		? ) print_usage ; exit 1 ;;
+	esac
+done
+shift $(($OPTIND - 1))
+
+tmpfile=$(mktemp -t dpdk.checknames.XXXXXX)
+trap 'rm -f -- "$tmpfile"' INT TERM HUP EXIT
+
+check_wordlist tier1.txt "Tier 1: Replace immediately"
+errors=$?
+
+check_wordlist tier2.txt "Tier 2: Strongly consider replacing"
+warnings=$?
+
+check_wordlist tier3.txt "Tier 3: Recommend to replace"
+suggestions=$?
+
+if [ -z "$lines" ] ; then
+    echo -n "Total lines: "
+else
+    echo -n "Total files: "
+fi
+
+echo $errors "errors," $warnings "warnings," $suggestions "suggestions"
+exit $errors
devtools/naming/tier1.txt new file +8 -0
new file mode 100644
index 000000000000..46532f2b234b
@@ -0,0 +1,8 @@
+abort
+blackhat
+whitehat
+cipple
+master
+slave
+whitelist
+blacklist
devtools/naming/tier2.txt new file +1 -0
new file mode 100644
index 000000000000..cd4280d1625c
@@ -0,0 +1 @@
+sanity
devtools/naming/tier3.txt new file +3 -0
new file mode 100644
index 000000000000..0f9586ff5bac
@@ -0,0 +1,3 @@
+man.in.the.middle
+segregate
+tribe
Signature · 1 line
2.39.2
#1 lore raw

PATCH v2 1/1 devtools: add script to check for non inclusive naming

Shell script to find use of words that not be used. By default it prints matches. The -q (quiet) option is used to just count. There is also -l option which lists lines matching (like grep -l).

Uses the word lists from Inclusive Naming Initiative see https://inclusivenaming.org/word-lists/

Examples:

 $ ./devtools/check-naming-policy.sh -q
 Total files: 37 errors, 90 warnings, 2 suggestions
 $ ./devtools/check-naming-policy.sh -q -l lib/eal
 Total lines: 32 errors, 8 warnings, 0 suggestions

Add MAINTAINERS file entry for the new tool and resort the list files back into to alphabetic order

---
v2 - fix typo in words
- add subtree (pathspec) option
- update maintainers file (and fix alphabetic order)

 MAINTAINERS                     |   8 ++-
 devtools/check-naming-policy.sh | 107 ++++++++++++++++++++++++++++++++
 devtools/naming/tier1.txt       |   8 +++
 devtools/naming/tier2.txt       |   1 +
 devtools/naming/tier3.txt       |   4 ++
 5 files changed, 125 insertions(+), 3 deletions(-)
 create mode 100755 devtools/check-naming-policy.sh
 create mode 100644 devtools/naming/tier1.txt
 create mode 100644 devtools/naming/tier2.txt
 create mode 100644 devtools/naming/tier3.txt
MAINTAINERS +5 -3
index 8df23e50999f..b5881113ba85 100644
@@ -83,26 +83,28 @@ Developers and Maintainers Tools
 M: Thomas Monjalon <[email protected]>
 F: MAINTAINERS
 F: devtools/build-dict.sh
-F: devtools/check-abi.sh
 F: devtools/check-abi-version.sh
+F: devtools/check-abi.sh
 F: devtools/check-doc-vs-code.sh
 F: devtools/check-dup-includes.sh
-F: devtools/check-maintainers.sh
 F: devtools/check-forbidden-tokens.awk
 F: devtools/check-git-log.sh
+F: devtools/check-maintainers.sh
+F: devtools/check-naming-policy.sh
 F: devtools/check-spdx-tag.sh
 F: devtools/check-symbol-change.sh
 F: devtools/check-symbol-maps.sh
 F: devtools/checkpatches.sh
 F: devtools/get-maintainer.sh
 F: devtools/git-log-fixes.sh
+F: devtools/libabigail.abignore
 F: devtools/load-devel-config
+F: devtools/naming/
 F: devtools/parse-flow-support.sh
 F: devtools/process-iwyu.py
 F: devtools/update-abi.sh
 F: devtools/update-patches.py
 F: devtools/update_version_map_abi.py
-F: devtools/libabigail.abignore
 F: devtools/words-case.txt
 F: license/
 F: .editorconfig
devtools/check-naming-policy.sh new file +107 -0

107 lines not on this page · raw message

devtools/naming/tier1.txt new file +8 -0
new file mode 100644
index 000000000000..a0e9b549c218
@@ -0,0 +1,8 @@
+abort
+blackhat
+blacklist
+cripple
+master
+slave
+whitehat
+whitelist
devtools/naming/tier2.txt new file +1 -0
new file mode 100644
index 000000000000..cd4280d1625c
@@ -0,0 +1 @@
+sanity
devtools/naming/tier3.txt new file +4 -0
new file mode 100644
index 000000000000..072f6468ea47
@@ -0,0 +1,4 @@
+man.in.the.middle
+segregate
+segregation
+tribe
Signature · 1 line
2.39.2
#2 lore raw
Quoted 16 lines · Stephen Hemminger

Shell script to find use of words that not be used. By default it prints matches. The -q (quiet) option is used to just count. There is also -l option which lists lines matching (like grep -l).

Uses the word lists from Inclusive Naming Initiative see https://inclusivenaming.org/word-lists/

Examples:

 $ ./devtools/check-naming-policy.sh -q
 Total files: 37 errors, 90 warnings, 2 suggestions
 $ ./devtools/check-naming-policy.sh -q -l lib/eal
 Total lines: 32 errors, 8 warnings, 0 suggestions
Quoted 8 lines

Add MAINTAINERS file entry for the new tool and resort the list files back into to alphabetic order

---
v2 - fix typo in words
- add subtree (pathspec) option
- update maintainers file (and fix alphabetic order)

There's a json file on the website, how about downloading that on the fly rather than storing a local copy that will go out of date?
https://inclusivenaming.org/word-lists/index.json

#3 lore raw
Quoted 27 lines · On Tue, 4 Apr 2023 00:08:30 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 16 lines · Stephen Hemminger

Shell script to find use of words that not be used. By default it prints matches. The -q (quiet) option is used to just count. There is also -l option which lists lines matching (like grep -l).

Uses the word lists from Inclusive Naming Initiative see https://inclusivenaming.org/word-lists/

Examples:

 $ ./devtools/check-naming-policy.sh -q
 Total files: 37 errors, 90 warnings, 2 suggestions
 $ ./devtools/check-naming-policy.sh -q -l lib/eal
 Total lines: 32 errors, 8 warnings, 0 suggestions
Quoted 8 lines

Add MAINTAINERS file entry for the new tool and resort the list files back into to alphabetic order

---
v2 - fix typo in words
- add subtree (pathspec) option
- update maintainers file (and fix alphabetic order)

Quoted 3 lines

There's a json file on the website, how about downloading that on the fly rather than storing a local copy that will go out of date?
https://inclusivenaming.org/word-lists/index.json

Ok, but that would mean using python and would also mean that terms like segreation which are not on the official list would not be caught

#4 lore raw
Quoted 30 lines · Stephen Hemminger
Quoted 27 lines · On Tue, 4 Apr 2023 00:08:30 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 24 lines · Stephen Hemminger

Shell script to find use of words that not be used. By default it prints matches. The -q (quiet) option is used to just count. There is also -l option which lists lines matching (like grep -l).

Uses the word lists from Inclusive Naming Initiative see https://inclusivenaming.org/word-lists/

Examples:

 $ ./devtools/check-naming-policy.sh -q
 Total files: 37 errors, 90 warnings, 2 suggestions
 $ ./devtools/check-naming-policy.sh -q -l lib/eal
 Total lines: 32 errors, 8 warnings, 0 suggestions

Add MAINTAINERS file entry for the new tool and resort the list files back into to alphabetic order

---
v2 - fix typo in words
   - add subtree (pathspec) option
   - update maintainers file (and fix alphabetic order)

Quoted 6 lines
Quoted 3 lines

There's a json file on the website, how about downloading that on the fly rather than storing a local copy that will go out of date?
https://inclusivenaming.org/word-lists/index.json

Ok, but that would mean using python and would also mean that terms like segreation which are not on the official list would not be caught

No need for python, it can be done with 'jq' very easily. Also there's 'segregate' which is close enough, it's tier 3. eg:

$ wget https://inclusivenaming.org/word-lists/index.json -q -O- | jq -r '.data[] | select ((.tier == "3")) | .term'
man-in-the-middle
Segregate
Signature · 2 lines
Kind regards,
Luca Boccassi
#5 lore raw
Quoted 10 lines · On Tue, 04 Apr 2023 23:00:42 +0100 Luca Boccassi <[email protected]> wrote:
Quoted 3 lines

Ok, but that would mean using python and would also mean that terms like segreation which are not on the official list would not be caught

No need for python, it can be done with 'jq' very easily. Also there's 'segregate' which is close enough, it's tier 3. eg:

$ wget https://inclusivenaming.org/word-lists/index.json -q -O- | jq -r '.data[] | select ((.tier == "3")) | .term'
man-in-the-middle
Segregate

Doing it in python allows for better UI. And makes it easier to do enhancements like show tier 1 only, or add more words on command line, or exclude additional directories.

Feature creep can be fun...