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
|
#!/bin/bash
# run static code checks like pyflakes and pep8
set -eu
echo "1..7"
builddir=$(pwd)
cd "${srcdir:-.}"
fail=0
#
# pyflakes
#
PYFLAKES="python3 -m pyflakes"
if ! $PYFLAKES /dev/null >/dev/null 2>&1; then
echo "ok 1 pyflakes pkg tools # SKIP pyflakes3 not installed"
elif $PYFLAKES tools/build-debian-copyright tools/npm-release-time >&2; then
echo "ok 1 pyflakes pkg tools"
else
echo "not ok 1 pyflakes pkg tools"
fail=1
fi
# TODO: there are currently a lot of pyflakes errors like
# 'parent' imported but unused
# 'from testlib import *' used; unable to detect undefined names
# Filter these out until these get fixed properly.
if ! $PYFLAKES /dev/null >/dev/null 2>&1; then
echo "ok 2 pyflakes test # SKIP pyflakes3 not installed"
else
out=$($PYFLAKES test/ 2>&1 | grep -Ev "(unable to detect undefined names|defined from star imports|'parent' imported but unused)") || true
if [ -n "$out" ]; then
echo "$out" >&2
echo "not ok 2 pyflakes test"
fail=1
else
echo "ok 2 pyflakes test"
fi
fi
#
# wrongly marked translatable strings
#
if out=$(find src/ pkg/ -name '*.js' -o -name '*.jsx' | xargs grep -n -E "(gettext|_)\(['\`]"); then
echo 'ERROR: translatable strings must be marked with _("")' >&2
echo "$out" >&2
echo "not ok 3 js-translatable-strings"
fail=1
elif out=$(grep -r 'translatable=["'\'']yes' pkg/ doc/); then
echo "ERROR: 'translatable' HTML attribute is invalid, use 'translate' instead"
echo "$out" >&2
echo "not ok 3 js-translatable-strings"
fail=1
else
echo "ok 3 js-translatable-strings"
fi
#
# Unsafe content-security-policy
#
# It's dangerous to have 'unsafe-inline' or 'unsafe-eval' in our
# content-security-policy entries. This is the browser equivalent
# of setenforce 0
shopt -s nullglob
safe=yes
for d in pkg/*; do
if ! test -f "$d"/content-security-policy.override; then
if grep -HE 'content-security-policy.*(\*|unsafe)' "$d"/*.json* /dev/null; then
safe="no"
fi
fi
done
if [ $safe == "no" ]; then
echo "not ok 4 unsafe-security-policy"
fail=1
else
echo "ok 4 unsafe-security-policy"
fi
#
# Bad paths or modifications in patternfly for fonts
#
if grep "\.\./fonts/OpenSans\|fonts/.*eot\|truetype" `ls dist/*/*.css $builddir/dist/*/*.css` >&2; then
echo "ERROR: invalid patternfly fonts paths found" >&2
echo "not ok 5 patternfly-font-paths"
fail=1
else
echo "ok 5 patternfly-font-paths"
fi
# Valid JSON files
if [ -e .git ]; then
for f in $(git ls-tree --name-only -r --full-name HEAD | grep '\.json$'); do
if ! python3 -m json.tool $f /dev/null; then
echo "ERROR: $f is invalid JSON" >&2
echo "not ok 6 json-verify"
fail=1
fi
done
echo "ok 6 json-verify"
else
echo "ok 6 json-verify # SKIP not a git tree"
fi
# pycodestyle/pep8 python syntax check
if python3 -m pycodestyle /dev/null >/dev/null 2>&1; then
PYTHON_STYLE_CHECKER="pycodestyle"
elif python3 -m pep8 /dev/null >/dev/null 2>&1; then
PYTHON_STYLE_CHECKER="pep8"
fi
if [ -z "${PYTHON_STYLE_CHECKER-}" ]; then
echo "ok 7 pycodestyle test # SKIP pycodestyle not installed"
else
# FIXME: Fix code for the warnings and re-enable them
out=$(python3 -m "$PYTHON_STYLE_CHECKER" --ignore E501,E265,E261,W504,W605 test/* --exclude=test/verify/nested-kvm,test/README.md,test/run,test/main.fmf) || true
if [ -n "$out" ]; then
echo "$out" >&2
echo "not ok 7 $PYTHON_STYLE_CHECKER test"
fail=1
else
echo "ok 7 $PYTHON_STYLE_CHECKER test"
fi
fi
exit $fail
|