devtools: add script to check for non inclusive naming
Checks
Commit Message
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/
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
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
new file mode 100755
@@ -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
new file mode 100644
@@ -0,0 +1,8 @@
+abort
+blackhat
+whitehat
+cipple
+master
+slave
+whitelist
+blacklist
new file mode 100644
@@ -0,0 +1 @@
+sanity
new file mode 100644
@@ -0,0 +1,3 @@
+man.in.the.middle
+segregate
+tribe