check.sh 1.5 KB

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