Skip to content

Commit cb66c52

Browse files
matttbekuba-moo
authored andcommitted
tests: pylint/shellcheck/yamllint: shellcheck compliant
It sounds good to have the script checking for shellcheck compliance to be shellcheck compliant :) While at it, pylint and yamllint scripts have also be modified because they are inspired by the shellcheck one. Before the modifications, shellcheck was complaining about: 53 note: Double quote to prevent globbing and word splitting. [SC2086] 4 warning: Quote this to prevent word splitting. [SC2046] 3 error: Argument mixes string and array. Use * or separate argument. [SC2145] 2 warning: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. [SC2164] Not any more. Also fix the indentation around the 'diff' at the end of each script, and in shellcheck.sh, s/Building/Checking/ like the others. Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent 58e7f5b commit cb66c52

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

tests/patch/pylint/pylint.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ HEAD=$(git rev-parse HEAD)
55
rc=0
66

77
pr() {
8-
echo " ====== $@ ======" | tee -a /dev/stderr
8+
echo " ====== $* ======" | tee -a /dev/stderr
99
}
1010

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

@@ -30,35 +30,35 @@ git checkout -q HEAD~
3030

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

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

3939
pr "Checking the tree with the patch"
40-
git checkout -q $HEAD
40+
git checkout -q "$HEAD"
4141

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

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

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

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

5454
rc=250
5555
fi
5656

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

61-
rc=1
61+
rc=1
6262
fi
6363

6464
rm "$tmpfile_o" "$tmpfile_n"

tests/patch/shellcheck/shellcheck.sh

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ HEAD=$(git rev-parse HEAD)
55
rc=0
66

77
pr() {
8-
echo " ====== $@ ======" | tee -a /dev/stderr
8+
echo " ====== $* ======" | tee -a /dev/stderr
99
}
1010

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

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

38-
cd $(dirname $f)
38+
cd "$(dirname "$f")" || exit 1
3939
sha="${tmpfile_o}_${sha}"
4040
rm -f "${sha}"
41-
shellcheck -x $(basename $f) | tee -a "${tmpfile_o}" "${sha}"
41+
shellcheck -x "$(basename "$f")" | tee -a "${tmpfile_o}" "${sha}"
4242
echo
4343
)
4444
done
4545

4646
# ex: SC3045 (warning): In POSIX sh, printf -v is undefined.
4747
# severity: error, warning, info, style
48-
incumbent=$(grep -c " (error):" $tmpfile_o)
49-
incumbent_w=$(grep -c " (warning):" $tmpfile_o)
48+
incumbent=$(grep -c " (error):" "$tmpfile_o")
49+
incumbent_w=$(grep -c " (warning):" "$tmpfile_o")
5050

51-
pr "Building the tree with the patch"
52-
git checkout -q $HEAD
51+
pr "Checking the tree with the patch"
52+
git checkout -q "$HEAD"
5353

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

60-
cd $(dirname $f)
60+
cd "$(dirname "$f")" || exit 1
6161
sha="${tmpfile_n}_${sha}"
6262
rm -f "${sha}"
63-
shellcheck -x $(basename $f) | tee -a "${tmpfile_n}" "${sha}"
63+
shellcheck -x "$(basename "$f")" | tee -a "${tmpfile_n}" "${sha}"
6464
echo
6565
)
6666
done
6767

6868
# severity: error, warning, info, style
69-
current=$(grep -c " (error):" $tmpfile_n)
70-
current_w=$(grep -c " (warning):" $tmpfile_n)
69+
current=$(grep -c " (error):" "$tmpfile_n")
70+
current_w=$(grep -c " (warning):" "$tmpfile_n")
7171

7272
# if a file was compliant before or is new, mark everything as error to keep it good.
7373
for f in "${tmpfile_n}_"*; do
@@ -88,19 +88,19 @@ for f in "${tmpfile_n}_"*; do
8888
current=$((current + extra))
8989
done
9090

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

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

9696
rc=250
9797
fi
9898

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

103-
rc=1
103+
rc=1
104104
fi
105105

106106
rm "$tmpfile_o"* "$tmpfile_n"*

tests/patch/yamllint/yamllint.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ HEAD=$(git rev-parse HEAD)
55
rc=0
66

77
pr() {
8-
echo " ====== $@ ======" | tee -a /dev/stderr
8+
echo " ====== $* ======" | tee -a /dev/stderr
99
}
1010

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

@@ -30,35 +30,35 @@ git checkout -q HEAD~
3030

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

36-
incumbent=$(grep -i -c " error " $tmpfile_o)
37-
incumbent_w=$(grep -i -c " warning " $tmpfile_o)
36+
incumbent=$(grep -i -c " error " "$tmpfile_o")
37+
incumbent_w=$(grep -i -c " warning " "$tmpfile_o")
3838

3939
pr "Checking the tree with the patch"
40-
git checkout -q $HEAD
40+
git checkout -q "$HEAD"
4141

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

46-
current=$(grep -i -c " error " $tmpfile_n)
47-
current_w=$(grep -i -c " warning " $tmpfile_n)
46+
current=$(grep -i -c " error " "$tmpfile_n")
47+
current_w=$(grep -i -c " warning " "$tmpfile_n")
4848

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

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

5454
rc=250
5555
fi
5656

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

61-
rc=1
61+
rc=1
6262
fi
6363

6464
rm "$tmpfile_o" "$tmpfile_n"

0 commit comments

Comments
 (0)