1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2022, deadc0de6
# stop on first error
set -eu -o errtrace -o pipefail
# ensure binaries are here
if ! which shellcheck >/dev/null 2>&1; then
echo "Install shellcheck"
exit 1
fi
echo "=> shellcheck version:"
shellcheck --version
# python tools versions
if ! which pylint >/dev/null 2>&1; then
echo "Install pylint"
exit 1
fi
echo "=> pylint version:"
pylint --version
if ! which pycodestyle >/dev/null 2>&1; then
echo "Install pycodestyle"
exit 1
fi
echo "=> pycodestyle version:"
pycodestyle --version
if ! which pyflakes >/dev/null 2>&1; then
echo "Install pyflakes"
exit 1
fi
echo "=> pyflakes version:"
pyflakes --version
# checking for TODO/FIXME
echo "--------------------------------------"
echo "checking for TODO/FIXME"
set +e
grep -r 'TODO\|FIXME' dotdrop/ && exit 1
grep -r 'TODO\|FIXME' tests/ && exit 1
grep -r 'TODO\|FIXME' tests-ng/ && exit 1
#grep -r 'TODO\|FIXME' scripts/ && exit 1
set -e
# checking for tests options
echo "---------------------------------"
echo "checking for bash strict mode"
find tests-ng -iname '*.sh' | while read -r script; do
#grep 'set +e' "${script}" 2>&1 >/dev/null && echo "set +e found in ${script}" && exit 1
grep 'set -eu -o errtrace -o pipefail' "${script}" >/dev/null 2>&1 || \
(echo "\"set -eu -o errtrace -o pipefail\" not set in ${script}" && exit 1 )
done
# PEP8 tests
# W503: Line break occurred before a binary operator
# W504: Line break occurred after a binary operator
echo "---------------------------------"
echo "checking dotdrop with pycodestyle"
pycodestyle --ignore=W503,W504 dotdrop/
pycodestyle scripts/
# pyflakes tests
echo "------------------------------"
echo "checking dotdrop with pyflakes"
pyflakes dotdrop/
# pylint
echo "----------------------------"
echo "checking dotdrop with pylint"
# https://pylint.pycqa.org/en/latest/user_guide/checkers/features.html
# R0902: too-many-instance-attributes
# R0913: too-many-arguments
# R0903: too-few-public-methods
# R0914: too-many-locals
# R0915: too-many-statements
# R0912: too-many-branches
# R0911: too-many-return-statements
# R0904: too-many-public-methods
# R0917: too-many-positional-arguments
pylint \
--disable=W0012 \
--disable=R0902 \
--disable=R0913 \
--disable=R0903 \
--disable=R0914 \
--disable=R0915 \
--disable=R0912 \
--disable=R0911 \
--disable=R0904 \
--disable=R0917 \
dotdrop/
# check shell scripts
# SC2002: Useless cat
# SC2126: Consider using grep -c instead of grep|wc -l
# SC2129: Consider using { cmd1; cmd2; } >> file instead of individual redirects
# SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?
# SC1004: This backslash+linefeed is literal. Break outside single quotes if you just want to break the line
echo "--------------------------------------"
echo "checking shell scripts with shellcheck"
find . -iname '*.sh' | while read -r script; do
echo "checking ${script}"
shellcheck -x \
-e SC2002 \
-e SC2126 \
-e SC2129 \
-e SC2181 \
-e SC1004 \
-e SC1117 \
-e SC2230 \
"${script}"
done
# check other python scripts
echo "-----------------------------------------"
echo "checking other python scripts with pylint"
find . -name "*.py" -not -path "./dotdrop/*" -not -regex "\./\.?v?env/.*" | while read -r script; do
echo "checking ${script}"
pylint -sn \
--disable=W0012 \
--disable=R0914 \
--disable=R0915 \
--disable=R0913 \
--disable=R0917 \
"${script}"
done
echo "------------------------"
echo "checking for more issues"
exceptions="save_uservariables_name\|@@\|diff_cmd\|original,\|modified,"
# f-string errors and missing f literal
find dotdrop/ -iname '*.py' -exec grep --with-filename -n -v "f'" {} \; | grep -v "{'" | grep -v "${exceptions}" | grep "'.*}" && echo "bad string format (1)" && exit 1
find dotdrop/ -iname '*.py' -exec grep --with-filename -n -v 'f"' {} \; | grep -v "f'" | grep -v '{"' | grep -v "${exceptions}" | grep '".*}' && echo "bad string format (2)" && exit 1
echo "syntax OK"
|