1#!/usr/bin/env bash 2 3# Copyright 2019 Alexandre Abadie <alexandre.abadie@inria.fr> 4# 5# This file is subject to the terms and conditions of the GNU Lesser 6# General Public License v2.1. See the file LICENSE in the top level 7# directory for more details. 8 9CODESPELL_CMD="codespell" 10 11if tput colors &> /dev/null && [ "$(tput colors)" -ge 8 ]; then 12 CERROR=$'\033[1;31m' 13 CRESET=$'\033[0m' 14else 15 CERROR= 16 CRESET= 17fi 18 19: "${LWIPBASE:=$(cd $(dirname $0)/; pwd)}" 20cd $LWIPBASE 21 22: "${LWIPTOOLS:=${LWIPBASE}}" 23. "${LWIPTOOLS}"/codespell_changed_files.sh 24 25FILEREGEX='\.([CcHh]|sh|py|md|txt)$' 26EXCLUDE='^(./contrib/apps/LwipMibCompiler/Mibs)' 27FILES=$(FILEREGEX=${FILEREGEX} EXCLUDE=${EXCLUDE} changed_files) 28 29if [ -z "${FILES}" ]; then 30 exit 0 31fi 32 33${CODESPELL_CMD} --version &> /dev/null || { 34 printf "%s%s: cannot execute \"%s\"!%s\n" "${CERROR}" "$0" "${CODESPELL_CMD}" "${CRESET}" 35 exit 1 36} 37 38CODESPELL_OPTS="-q 2" # Disable "WARNING: Binary file" 39CODESPELL_OPTS+=" --check-hidden" 40# Disable false positives "nd => and, 2nd", "ans => and", "tolen => token", 41# "ofo => of", "WAN => WANT", "mut => must, mutt, moot" 42CODESPELL_OPTS+=" --ignore-words-list=nd,ans,tolen,ofo,wan,mut,clen,useg,clos " 43CODESPELL_OPTS+=" --ignore-words-list=devine,clinet,linz,garantie,explicite,numer " 44CODESPELL_OPTS+=" --ignore-words-list=skool " 45# propagate all options to codespell -> pass "-w" to this script to write changes 46CODESPELL_OPTS+="$@" 47 48# Filter-out all false positive raising "disabled due to" messages. 49ERRORS=$(${CODESPELL_CMD} ${CODESPELL_OPTS} ${FILES} | grep -ve "disabled due to") 50 51if [ -n "${ERRORS}" ] 52then 53 printf "%sThere are typos in the following files:%s\n\n" "${CERROR}" "${CRESET}" 54 printf "%s\n" "${ERRORS}" 55 # TODO: return 1 when all typos are fixed 56 exit 0 57else 58 exit 0 59fi 60