summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-10-11 16:48:21 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-11-01 21:56:21 +0900
commit3f022e8075153a637e96ba80ee2ca537ebe6004a (patch)
tree71366e79c9946caa4cfd6ae8d2ad049c6d76a427 /tools
parent6f88f352e4aa78a637f514fd0302ab7c98942640 (diff)
tools: Add script for spell checking
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/spell-check/README.md34
-rw-r--r--tools/spell-check/dictionary.txt42
-rw-r--r--tools/spell-check/ignore.txt33
-rwxr-xr-xtools/spell-check/scspell.sh96
4 files changed, 205 insertions, 0 deletions
diff --git a/tools/spell-check/README.md b/tools/spell-check/README.md
new file mode 100644
index 00000000..2b2800a6
--- /dev/null
+++ b/tools/spell-check/README.md
@@ -0,0 +1,34 @@
+# What's this?
+
+This script is a spell checker for GoBGP's source codes.
+
+## Requirements
+
+- [scspell3k](https://pypi.python.org/pypi/scspell3k): Spell checker for
+source code written in Python.
+
+ ```bash
+ pip install scspell3k
+ ```
+
+## How to use
+
+Just run `scspell.sh `
+
+```bash
+bash tools/spell-check/scspell.sh
+```
+
+Example of output:
+
+```bash
+# Format:
+# path/to/file.go: <messages>
+xxx/xxx.go: 'mispeld' not found in dictionary (from token 'Mispeld')
+```
+
+## Adding new words to dictionary
+
+If you want to add new words to the dictionary for this spell checker, please
+insert words into `tools/spell-check/dictionary.txt` or
+`tools/spell-check/ignore.txt`.
diff --git a/tools/spell-check/dictionary.txt b/tools/spell-check/dictionary.txt
new file mode 100644
index 00000000..fd4897ee
--- /dev/null
+++ b/tools/spell-check/dictionary.txt
@@ -0,0 +1,42 @@
+NATURAL:
+afisafi
+aggregator
+aigp
+aspath
+bgpd
+cidr
+distinguisher
+dscp
+ebgp
+ethernet
+evpn
+flowspec
+gobgp
+gobgpd
+grpc
+ibgp
+ipproto
+keepalive
+keepalives
+llgr
+localhost
+mpls
+multicast
+multihop
+multipath
+mututally
+nexthop
+nexthops
+nlri
+pmsi
+prepend
+reachability
+rpki
+sadb
+safi
+subcode
+syscall
+syslog
+unicast
+uptime
+zapi
diff --git a/tools/spell-check/ignore.txt b/tools/spell-check/ignore.txt
new file mode 100644
index 00000000..4163d941
--- /dev/null
+++ b/tools/spell-check/ignore.txt
@@ -0,0 +1,33 @@
+# Words should be ignored and too specific for adding to dictionary.txt
+# Hexadecimal number
+ffff
+FFFF
+
+# Function name
+Debugf
+epoll
+Errorf
+Fatalf
+getpid
+getsockopt
+Infof
+itoa
+setsockopt
+Sprintf
+strconv
+
+# Implementation specific
+dumpv2
+elems
+etag
+Extcomms
+fdinfo
+ifindex
+ifname
+linktype
+macadv
+Rcvd
+Receivedv4
+Receivedv6
+softreset
+stmt
diff --git a/tools/spell-check/scspell.sh b/tools/spell-check/scspell.sh
new file mode 100755
index 00000000..c841eced
--- /dev/null
+++ b/tools/spell-check/scspell.sh
@@ -0,0 +1,96 @@
+#!/usr/bin/env bash
+
+SCRIPT_DIR=`dirname $0`
+GOBGP=${SCRIPT_DIR}/../../
+
+FUNCS=(
+Debug
+Debugf
+Debugln
+Error
+Errorf
+Errorln
+Fatal
+Fatalf
+Fatalln
+Fprint
+Fprintf
+Fprintln
+Info
+Infof
+Infoln
+Panic
+Panicf
+Panicln
+Print
+Printf
+Println
+Sprint
+Sprintf
+Sprintln
+Warn
+Warnf
+Warning
+Warningf
+Warningln
+Warnln
+)
+
+CHECK_LOG=/tmp/gobgp/scspell.log
+mkdir -p `dirname ${CHECK_LOG}`
+rm -f ${CHECK_LOG} # Clean up previous output
+
+# Do find *.go files except under vendor directory
+for FILE in `find ${GOBGP} -type d -name vendor -prune -o -type f -name *.go | sort`
+do
+ TMP_FILE=${FILE/${GOBGP}//tmp/gobgp/}
+ mkdir -p `dirname ${TMP_FILE}`
+ rm -f ${TMP_FILE} # Clean up previous output
+
+ for FUNC in ${FUNCS[@]}
+ do
+ # Do grep cases like:
+ # fmt.Print("...")
+ # or
+ # fmt.Print(
+ # "...")
+ grep ${FUNC}'("' ${FILE} | grep -o '".*"' >> ${TMP_FILE}
+ grep ${FUNC}'($' -A 1 ${FILE} | grep -o '".*"' >> ${TMP_FILE}
+ done
+
+ # If any case found
+ if [ -s ${TMP_FILE} ]
+ then
+ # Apply exclude rules defined in ignore.txt
+ for WORD in `grep -v -e '^\s*#' -e '^$' ${SCRIPT_DIR}/ignore.txt`
+ do
+ sed -i "s/${WORD}//g" ${TMP_FILE}
+ done
+
+ # Do scspell with dictionary.txt and reformat messages
+ scspell \
+ --use-builtin-base-dict \
+ --override-dictionary ${SCRIPT_DIR}/dictionary.txt \
+ --report-only \
+ ${TMP_FILE} 2>&1 \
+ | tee -a ${CHECK_LOG} \
+ | sed "s/\/tmp\/gobgp\///" | cut -d ':' -f -1,3-
+ fi
+
+ #rm ${TMP_FILE}
+done
+
+RESULT=0
+
+# If any output of scspell exists
+if [ -s ${CHECK_LOG} ]
+then
+ echo "---"
+ echo "See ${CHECK_LOG} for more details."
+ # Set return code as error
+ RESULT=1
+fi
+
+#rm -f ${CHECK_LOG}
+exit ${RESULT}
+