Skip to content

Shellcheck warnings #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions tests/patch/pylint/pylint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ HEAD=$(git rev-parse HEAD)
rc=0

pr() {
echo " ====== $@ ======" | tee -a /dev/stderr
echo " ====== $* ======" | tee -a /dev/stderr
}

# If it doesn't touch .py files, don't bother. Ignore deleted.
if ! git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -q -E "\.py$"
then
echo "No python scripts touched, skip" >&$DESC_FD
echo "No python scripts touched, skip" >&"$DESC_FD"
exit 0
fi

Expand All @@ -30,35 +30,35 @@ git checkout -q HEAD~

# Also ignore created, as not present in the parent commit
for f in $(git show --diff-filter=M --pretty="" --name-only "${HEAD}" | grep -E "\.py$"); do
pylint $f | tee -a $tmpfile_o
pylint "$f" | tee -a "$tmpfile_o"
done

incumbent=$(grep -i -c ": E[0-9][0-9][0-9][0-9]: " $tmpfile_o)
incumbent_w=$(grep -i -c ": [WC][0-9][0-9][0-9][0-9]: " $tmpfile_o)
incumbent=$(grep -i -c ": E[0-9][0-9][0-9][0-9]: " "$tmpfile_o")
incumbent_w=$(grep -i -c ": [WC][0-9][0-9][0-9][0-9]: " "$tmpfile_o")

pr "Checking the tree with the patch"
git checkout -q $HEAD
git checkout -q "$HEAD"

for f in $(git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -E "\.py$"); do
pylint $f | tee -a $tmpfile_n
pylint "$f" | tee -a "$tmpfile_n"
done

current=$(grep -i -c ": E[0-9][0-9][0-9][0-9]: " $tmpfile_n)
current_w=$(grep -i -c ": [WC][0-9][0-9][0-9][0-9]: " $tmpfile_n)
current=$(grep -i -c ": E[0-9][0-9][0-9][0-9]: " "$tmpfile_n")
current_w=$(grep -i -c ": [WC][0-9][0-9][0-9][0-9]: " "$tmpfile_n")

echo "Errors before: $incumbent (+warn: $incumbent_w) this patch: $current (+warn: $current_w)" >&$DESC_FD
echo "Errors before: $incumbent (+warn: $incumbent_w) this patch: $current (+warn: $current_w)" >&"$DESC_FD"

if [ $current -gt $incumbent ]; then
echo "New errors added" 1>&2
diff -U 0 $tmpfile_o $tmpfile_n 1>&2
if [ "$current_w" -gt "$incumbent_w" ]; then
echo "New warnings added" 1>&2

rc=1
rc=250
fi

if [ $current_w -gt $incumbent_w ]; then
echo "New warnings added" 1>&2
if [ "$current" -gt "$incumbent" ]; then
echo "New errors added" 1>&2
diff -U 0 "$tmpfile_o" "$tmpfile_n" 1>&2

rc=250
rc=1
fi

rm "$tmpfile_o" "$tmpfile_n"
Expand Down
72 changes: 50 additions & 22 deletions tests/patch/shellcheck/shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ HEAD=$(git rev-parse HEAD)
rc=0

pr() {
echo " ====== $@ ======" | tee -a /dev/stderr
echo " ====== $* ======" | tee -a /dev/stderr
}

# If it doesn't touch .sh files, don't bother. Ignore deleted.
if ! git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -q -E "\.sh$"
then
echo "No shell scripts touched, skip" >&$DESC_FD
echo "No shell scripts touched, skip" >&"$DESC_FD"
exit 0
fi

Expand All @@ -31,50 +31,78 @@ git checkout -q HEAD~
# Also ignore created, as not present in the parent commit
for f in $(git show --diff-filter=M --pretty="" --name-only "${HEAD}" | grep -E "\.sh$"); do
(
echo "Checking $f"
sha=$(echo "$f" | sha256sum | awk '{print $1}')
echo "Checking $f - $sha"
echo

cd $(dirname $f)
shellcheck -x $(basename $f) | tee -a $tmpfile_o
cd "$(dirname "$f")" || exit 1
sha="${tmpfile_o}_${sha}"
rm -f "${sha}"
shellcheck -x "$(basename "$f")" | tee -a "${tmpfile_o}" "${sha}"
echo
)
done

incumbent=$(grep -i -c "(error)" $tmpfile_o)
incumbent_w=$(grep -i -c "SC[0-9]* (" $tmpfile_o)
# ex: SC3045 (warning): In POSIX sh, printf -v is undefined.
# severity: error, warning, info, style
incumbent=$(grep -c " (error):" "$tmpfile_o")
incumbent_w=$(grep -c " (warning):" "$tmpfile_o")

pr "Building the tree with the patch"
git checkout -q $HEAD
pr "Checking the tree with the patch"
git checkout -q "$HEAD"

for f in $(git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -E "\.sh$"); do
(
echo "Checking $f"
sha=$(echo "$f" | sha256sum | awk '{print $1}')
echo "Checking $f - $sha"
echo

cd $(dirname $f)
shellcheck -x $(basename $f) | tee -a $tmpfile_n
cd "$(dirname "$f")" || exit 1
sha="${tmpfile_n}_${sha}"
rm -f "${sha}"
shellcheck -x "$(basename "$f")" | tee -a "${tmpfile_n}" "${sha}"
echo
)
done

current=$(grep -i -c "(error)" $tmpfile_n)
current_w=$(grep -i -c "SC[0-9]* (" $tmpfile_n)
# severity: error, warning, info, style
current=$(grep -c " (error):" "$tmpfile_n")
current_w=$(grep -c " (warning):" "$tmpfile_n")

echo "Errors before: $incumbent (+warn: $incumbent_w) this patch: $current (+warn: $current_w)" >&$DESC_FD
# if a file was compliant before or is new, mark everything as error to keep it good.
for f in "${tmpfile_n}_"*; do
[ ! -s "${f}" ] && continue # still compliant

if [ $current -gt $incumbent ]; then
echo "New errors added" 1>&2
diff -U 0 $tmpfile_o $tmpfile_n 1>&2
sha="${f:${#tmpfile_n}+1}"
old="${tmpfile_o}_${sha}"
[ -s "${old}" ] && continue # wasn't compliant

rc=1
fi
fname=$(head -n2 "${f}" | tail -n1 | sed "s/^In \(\S\+\.sh\) line [0-9]\+:/\1/g")
if [ -f "${old}" ]; then
echo "${fname} was shellcheck compliant, not anymore" 1>&2
else
echo "${fname} is a new file, but not shellcheck compliant" 1>&2
fi

extra=$(grep -c -E " \((warning|info|style)\):" "${f}")
current=$((current + extra))
done

echo "Errors before: $incumbent (+warn: $incumbent_w) this patch: $current (+warn: $current_w)" >&"$DESC_FD"

if [ $current_w -gt $incumbent_w ]; then
if [ "$current_w" -gt "$incumbent_w" ]; then
echo "New warnings added" 1>&2

rc=250
fi

rm "$tmpfile_o" "$tmpfile_n"
if [ "$current" -gt "$incumbent" ]; then
echo "New errors added" 1>&2
diff -U 0 "$tmpfile_o" "$tmpfile_n" 1>&2

rc=1
fi

rm "$tmpfile_o"* "$tmpfile_n"*

exit $rc
34 changes: 17 additions & 17 deletions tests/patch/yamllint/yamllint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ HEAD=$(git rev-parse HEAD)
rc=0

pr() {
echo " ====== $@ ======" | tee -a /dev/stderr
echo " ====== $* ======" | tee -a /dev/stderr
}

# If it doesn't touch .yaml files, don't bother. Ignore deleted.
if ! git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -q -E "\.yaml$"
then
echo "No YAML files touched, skip" >&$DESC_FD
echo "No YAML files touched, skip" >&"$DESC_FD"
exit 0
fi

Expand All @@ -30,35 +30,35 @@ git checkout -q HEAD~

# Also ignore created, as not present in the parent commit
for f in $(git show --diff-filter=M --pretty="" --name-only "${HEAD}" | grep -E "\.yaml$"); do
yamllint $f | tee -a $tmpfile_o
yamllint "$f" | tee -a "$tmpfile_o"
done

incumbent=$(grep -i -c " error " $tmpfile_o)
incumbent_w=$(grep -i -c " warning " $tmpfile_o)
incumbent=$(grep -i -c " error " "$tmpfile_o")
incumbent_w=$(grep -i -c " warning " "$tmpfile_o")

pr "Checking the tree with the patch"
git checkout -q $HEAD
git checkout -q "$HEAD"

for f in $(git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -E "\.yaml$"); do
yamllint $f | tee -a $tmpfile_n
yamllint "$f" | tee -a "$tmpfile_n"
done

current=$(grep -i -c " error " $tmpfile_n)
current_w=$(grep -i -c " warning " $tmpfile_n)
current=$(grep -i -c " error " "$tmpfile_n")
current_w=$(grep -i -c " warning " "$tmpfile_n")

echo "Errors before: $incumbent (+warn: $incumbent_w) this patch: $current (+warn: $current_w)" >&$DESC_FD
echo "Errors before: $incumbent (+warn: $incumbent_w) this patch: $current (+warn: $current_w)" >&"$DESC_FD"

if [ $current -gt $incumbent ]; then
echo "New errors added" 1>&2
diff -U 0 $tmpfile_o $tmpfile_n 1>&2
if [ "$current_w" -gt "$incumbent_w" ]; then
echo "New warnings added" 1>&2

rc=1
rc=250
fi

if [ $current_w -gt $incumbent_w ]; then
echo "New warnings added" 1>&2
if [ "$current" -gt "$incumbent" ]; then
echo "New errors added" 1>&2
diff -U 0 "$tmpfile_o" "$tmpfile_n" 1>&2

rc=250
rc=1
fi

rm "$tmpfile_o" "$tmpfile_n"
Expand Down