Skip to content

Commit 7482a42

Browse files
committed
linting: shell: fix shellcheck warnings
Fix errors brought up by the linter. Signed-off-by: Andreas Hatziiliou <andreas.hatziiliou@savoirfairelinux.com>
1 parent 48e7070 commit 7482a42

File tree

6 files changed

+31
-33
lines changed

6 files changed

+31
-33
lines changed

META.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ META=META.yml
1717
# Manual extraction of metadata with basic cmd line tools
1818
VAL=$(cat $META |
1919
grep "name\|$2" |
20-
grep $1 -A 1 |
21-
grep $2 |
20+
grep "$1" -A 1 |
21+
grep "$2" |
2222
cut -d ":" -f 2 | tr -d ' ')
2323

2424
# More robust extraction using yq
25-
if (which yq 2>&1 >/dev/null); then
25+
if (which yq >/dev/null 2>&1); then
2626
QUERY=".implementations | .[] | select(.name==\"$1\") | .\"$2\""
27-
echo "cat $META | yq "$QUERY" -r"
27+
echo "cat $META | yq \"$QUERY\" -r"
2828
VAL_JQ=$(cat $META | yq "$QUERY" -r)
2929

30-
if [[ $VAL_JQ != $VAL ]]; then
30+
if [[ $VAL_JQ != "$VAL" ]]; then
3131
echo "ERROR parsing metadata file $META"
3232
exit 1
3333
fi
@@ -43,5 +43,5 @@ if [[ $INPUT != "" ]]; then
4343
exit 0
4444
fi
4545
else
46-
echo $VAL
46+
echo "$VAL"
4747
fi

proofs/cbmc/list_proofs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
# which are those containing a *harness.c file.
77

88
ROOT=$(git rev-parse --show-toplevel)
9-
cd $ROOT
9+
cd "$ROOT" || exit
1010
ls -1 proofs/cbmc/**/*harness.c | cut -d '/' -f 3

proofs/hol_light/x86_64/list_proofs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
# we have a spec and proof in HOL-Light.
77

88
ROOT=$(git rev-parse --show-toplevel)
9-
cd $ROOT
9+
cd "$ROOT" || exit
1010
ls -1 proofs/hol_light/x86_64/mldsa/*.S | cut -d '/' -f 5 | sed 's/\.S//'

proofs/hol_light/x86_64/proofs/build-proof.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ output_path=$3
3434
output_dir=$(dirname "$output_path")
3535
[ -d "$output_dir" ] || mkdir -p "$output_dir"
3636

37-
export HOLLIGHT_DIR="$(dirname ${hol_sh_cmd})"
37+
HOLLIGHT_DIR="$(dirname "${hol_sh_cmd}")"
38+
export HOLLIGHT_DIR
3839
if [ ! -f "${HOLLIGHT_DIR}/hol_lib.cmxa" ]; then
3940
echo "hol_lib.cmxa does not exist in HOLLIGHT_DIR('${HOLLIGHT_DIR}')."
4041
echo "Did you compile HOL Light with HOLLIGHT_USE_MODULE set to 1?"
@@ -50,20 +51,20 @@ echo "Generating a template .ml that loads the file...: ${template_ml}"
5051
echo "check_axioms ();;"
5152
echo 'let proof_end_time = Unix.time();;'
5253
echo 'Printf.printf "Running time: %f sec, Start unixtime: %f, End unixtime: %f\n" (proof_end_time -. proof_start_time) proof_start_time proof_end_time;;'
53-
) >>${template_ml}
54+
) >>"${template_ml}"
5455

5556
inlined_prefix="$(mktemp)"
5657
inlined_ml="${inlined_prefix}.ml"
5758
inlined_cmx="${inlined_prefix}.cmx"
58-
(cd "${S2N_BIGNUM_DIR}" && HOLLIGHT_LOAD_PATH=${ROOT} ocaml ${HOLLIGHT_DIR}/inline_load.ml "${template_ml}" "${inlined_ml}")
59+
(cd "${S2N_BIGNUM_DIR}" && HOLLIGHT_LOAD_PATH=${ROOT} ocaml "${HOLLIGHT_DIR}"/inline_load.ml "${template_ml}" "${inlined_ml}")
5960

6061
# Give a large stack size.
6162
OCAMLRUNPARAM=l=2000000000 \
6263
ocamlopt.byte -pp "$(${hol_sh_cmd} -pp)" -I "${HOLLIGHT_DIR}" -I +unix -c \
63-
hol_lib.cmxa ${inlined_ml} -o ${inlined_cmx} -w -a
64+
hol_lib.cmxa "${inlined_ml}" -o "${inlined_cmx}" -w -a
6465
ocamlfind ocamlopt -package zarith,unix -linkpkg hol_lib.cmxa \
65-
-I "${HOLLIGHT_DIR}" ${inlined_cmx} \
66+
-I "${HOLLIGHT_DIR}" "${inlined_cmx}" \
6667
-o "${output_path}"
6768

6869
# Remove the intermediate files to save disk space
69-
rm -f ${inlined_cmx} ${template_ml} ${inlined_ml}
70+
rm -f "${inlined_cmx}" "${template_ml}" "${inlined_ml}"

scripts/format

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ ROOT="$(realpath "$(dirname "$0")"/../)"
1313
# Standard color definitions
1414
GREEN="\033[32m"
1515
RED="\033[31m"
16-
BLUE="\033[94m"
17-
BOLD="\033[1m"
1816
NORMAL="\033[0m"
1917

2018
# utility
@@ -29,40 +27,40 @@ error()
2927
}
3028

3129
info "Formatting nix files"
32-
if ! command -v nixpkgs-fmt 2>&1 >/dev/null; then
30+
if ! command -v nixpkgs-fmt >/dev/null 2>&1; then
3331
error "nixpkgs-fmt not found. Are you running in a nix shell? See BUILDING.md."
3432
exit 1
3533
fi
3634

3735
nixpkgs-fmt "$ROOT"
3836

3937
info "Formatting shell scripts"
40-
if ! command -v shfmt 2>&1 >/dev/null; then
38+
if ! command -v shfmt >/dev/null 2>&1; then
4139
error "shfmt not found. Are you running in a nix shell? See BUILDING.md."
4240
exit 1
4341
fi
4442

4543
# Find all scripts in the repo
4644
ALL_FILES=$(git grep -l '' :/)
4745
SHELL_SCRIPTS=$(echo "$ALL_FILES" | xargs shfmt -f)
48-
shfmt -s -l -i 2 -ci -fn $SHELL_SCRIPTS
46+
echo $SHELL_SCRIPTS | xargs shfmt -s -w -l -i 2 -ci -fn
4947

5048
info "Formatting python scripts"
51-
if ! command -v black 2>&1 >/dev/null; then
49+
if ! command -v black >/dev/null 2>&1; then
5250
error "black not found. Are you running in a nix shell? See BUILDING.md."
5351
exit 1
5452
fi
5553
black --include "(scripts/tests|scripts/simpasm|scripts/cfify|scripts/autogen|scripts/check-namespace|\.py$)" "$ROOT"
5654

5755
info "Formatting c files"
58-
if ! command -v clang-format 2>&1 >/dev/null; then
56+
if ! command -v clang-format >/dev/null 2>&1; then
5957
error "clang-format not found. Are you running in a nix shell? See BUILDING.md."
6058
exit 1
6159
fi
6260

6361
nproc=$(getconf _NPROCESSORS_ONLN || echo 1)
6462

65-
git ls-files -- ":/*.c" ":/*.h" | xargs -P $nproc -I {} sh -c '
63+
git ls-files -- ":/*.c" ":/*.h" | xargs -P "$nproc" -I {} sh -c '
6664
# Ignore symlinks
6765
if [[ ! -L {} ]]; then
6866
clang-format -i {}
@@ -71,7 +69,7 @@ git ls-files -- ":/*.c" ":/*.h" | xargs -P $nproc -I {} sh -c '
7169
info "Checking for eol"
7270
check-eol()
7371
{
74-
git ls-files -- ":/" ":/!:*.png" | xargs -P $nproc -I {} sh -c '
72+
git ls-files -- ":/" ":/!:*.png" | xargs -P "$nproc" -I {} sh -c '
7573
# Ignore symlinks
7674
if [[ ! -L {} && $(tail -c1 "{}" | wc -l) == 0 ]]; then
7775
echo "" >>"{}"

scripts/lint

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ fi
2020
# Standard color definitions
2121
GREEN="\033[32m"
2222
RED="\033[31m"
23-
BLUE="\033[94m"
24-
BOLD="\033[1m"
2523
NORMAL="\033[0m"
2624

2725
info()
@@ -122,8 +120,9 @@ run-shellcheck()
122120
# Formatting
123121
SUCCESS=true
124122

125-
# Get list of shell scripts for linting
123+
# Get list of shell scripts and .c/.h files for linting
126124
ALL_FILES=$(git grep -l '' :/)
125+
ALL_C_FILES=$(git ls-files ":/*.c" ":/*.h")
127126
SHELL_SCRIPTS=$(echo "$ALL_FILES" | xargs shfmt -f)
128127

129128
gh_group_start "Linting nix files with nixpkgs-fmt"
@@ -151,7 +150,7 @@ fi
151150
gh_group_end
152151

153152
gh_group_start "Linting c files with clang-format"
154-
checkerr "Lint C" "$(clang-format $(git ls-files ":/*.c" ":/*.h") --Werror --dry-run 2>&1 | grep "error:" | cut -d ':' -f 1,2 | tr ':' ' ')"
153+
checkerr "Lint C" "$(echo $ALL_C_FILES | xargs clang-format --Werror --dry-run 2>&1 | grep "error:" | cut -d ':' -f 1,2 | tr ':' ' ')"
155154
gh_group_end
156155

157156
check-eol-dry-run()
@@ -173,22 +172,22 @@ check-spdx()
173172
local success=true
174173
for file in $(git ls-files -- ":/" ":/!:*.json" ":/!:*.png" ":/!:*LICENSE*" ":/!:.git*" ":/!:flake.lock"); do
175174
# Ignore symlinks
176-
if [[ ! -L $file && $(grep "SPDX-License-Identifier:" $file | wc -l) == 0 ]]; then
175+
if [[ ! -L $file && $(grep "SPDX-License-Identifier:" "$file" | wc -l) == 0 ]]; then
177176
gh_error "$file" "${line:-1}" "Missing license header error" "$file is missing SPDX License header"
178177
success=false
179178
fi
180179
done
181180
for file in $(git ls-files -- "*.[chsS]" "*.py" "*.mk" "*.yml" "**/Makefile*" ":/!proofs/cbmc/*.py" ":/!examples/bring_your_own_fips202/custom_fips202/tiny_sha3/*" ":/!examples/custom_backend/mldsa_native/src/fips202/native/custom/src/*"); do
182181
# Ignore symlinks
183-
if [[ ! -L $file && $(grep "Copyright (c) The mldsa-native project authors" $file | wc -l) == 0 ]]; then
182+
if [[ ! -L $file && $(grep "Copyright (c) The mldsa-native project authors" "$file" | wc -l) == 0 ]]; then
184183
gh_error "$file" "${line:-1}" "Missing copyright header error" "$file is missing copyright header"
185184
success=false
186185
fi
187186
done
188187
# For source files in dev/* and mldsa/*, we enforce `Apache-2.0 OR ISC OR MIT`
189188
for file in $(git ls-files -- "*.[chsSi]" | grep "^dev/\|^mldsa/"); do
190189
# Ignore symlinks
191-
if [[ ! -L $file && $(grep "SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT" $file | wc -l) == 0 ]]; then
190+
if [[ ! -L $file && $(grep "SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT" "$file" | wc -l) == 0 ]]; then
192191
gh_error "$file" "${line:-1}" "Missing license header error" "$file is not licensed under 'Apache-2.0 OR ISC OR MIT'"
193192
success=false
194193
fi
@@ -209,7 +208,7 @@ gh_group_end
209208

210209
check-autogenerated-files()
211210
{
212-
if python3 $ROOT/scripts/autogen --dry-run; then
211+
if python3 "$ROOT"/scripts/autogen --dry-run; then
213212
info "Check native auto-generated files"
214213
gh_summary_success "Check native auto-generated files"
215214
else
@@ -225,7 +224,7 @@ gh_group_end
225224

226225
check-magic()
227226
{
228-
if python3 $ROOT/scripts/check-magic >/dev/null; then
227+
if python3 "$ROOT"/scripts/check-magic >/dev/null; then
229228
info "Check magic constants"
230229
gh_summary_success "Check magic constants"
231230
else
@@ -245,7 +244,7 @@ fi
245244

246245
check-contracts()
247246
{
248-
if python3 $ROOT/scripts/check-contracts >/dev/null; then
247+
if python3 "$ROOT"/scripts/check-contracts >/dev/null; then
249248
info "Check contracts"
250249
gh_summary_success "Check contracts"
251250
else

0 commit comments

Comments
 (0)