2020# Standard color definitions
2121GREEN=" \033[32m"
2222RED=" \033[31m"
23- BLUE=" \033[94m"
24- BOLD=" \033[1m"
2523NORMAL=" \033[0m"
2624
2725info ()
@@ -106,15 +104,36 @@ gh_error_simple()
106104 fi
107105}
108106
107+ run-shellcheck ()
108+ {
109+ if ! command -v shellcheck > /dev/null; then
110+ gh_error_simple " Shellcheck missing" " shellcheck is not installed"
111+ error " Lint shellcheck"
112+ SUCCESS=false
113+ gh_summary_failure " Lint shellcheck"
114+ return 0
115+ fi
116+
117+ checkerr " Lint shellcheck" " $( shellcheck --severity=warning $SHELL_SCRIPTS ) "
118+ }
119+
109120# Formatting
110121SUCCESS=true
111122
123+ # Get list of shell scripts for linting
124+ ALL_FILES=$( git grep -l ' ' :/)
125+ SHELL_SCRIPTS=$( echo " $ALL_FILES " | xargs shfmt -f)
126+
112127gh_group_start " Linting nix files with nixpkgs-fmt"
113128checkerr " Lint nix" " $( nixpkgs-fmt --check " $ROOT " ) "
114129gh_group_end
115130
116131gh_group_start " Linting shell scripts with shfmt"
117- checkerr " Lint shell" " $( shfmt -s -l -i 2 -ci -fn $( shfmt -f $( git grep -l ' ' :/) ) ) "
132+ checkerr " Lint shell" " $( echo $SHELL_SCRIPTS | xargs shfmt -s -l -i 2 -ci -fn) "
133+ gh_group_end
134+
135+ gh_group_start " Linting shell scripts with shellcheck"
136+ run-shellcheck
118137gh_group_end
119138
120139gh_group_start " Linting python scripts with black"
130149gh_group_end
131150
132151gh_group_start " Linting c files with clang-format"
133- checkerr " Lint C" " $( clang-format $( git ls-files " :/*.c" " :/*.h" ) --Werror --dry-run 2>&1 | grep " error:" | cut -d ' :' -f 1,2 | tr ' :' ' ' ) "
152+ checkerr " Lint C" " $( clang-format " $( git ls-files " :/*.c" " :/*.h" ) " --Werror --dry-run 2>&1 | grep " error:" | cut -d ' :' -f 1,2 | tr ' :' ' ' ) "
134153gh_group_end
135154
136155check-eol-dry-run ()
@@ -152,22 +171,22 @@ check-spdx()
152171 local success=true
153172 for file in $( git ls-files -- " :/" " :/!:*.json" " :/!:*.png" " :/!:*LICENSE*" " :/!:.git*" " :/!:flake.lock" ) ; do
154173 # Ignore symlinks
155- if [[ ! -L $file && $( grep " SPDX-License-Identifier:" $file | wc -l) == 0 ]]; then
174+ if [[ ! -L $file && $( grep " SPDX-License-Identifier:" " $file " | wc -l) == 0 ]]; then
156175 gh_error " $file " " ${line:- 1} " " Missing license header error" " $file is missing SPDX License header"
157176 success=false
158177 fi
159178 done
160179 for file in $( git ls-files -- " *.[chsS]" " *.py" " *.mk" " *.yml" " **/Makefile*" " :/!proofs/cbmc/*.py" " :/!examples/bring_your_own_fips202/custom_fips202/tiny_sha3/*" ) ; do
161180 # Ignore symlinks
162- if [[ ! -L $file && $( grep " Copyright (c) The mldsa-native project authors" $file | wc -l) == 0 ]]; then
181+ if [[ ! -L $file && $( grep " Copyright (c) The mldsa-native project authors" " $file " | wc -l) == 0 ]]; then
163182 gh_error " $file " " ${line:- 1} " " Missing copyright header error" " $file is missing copyright header"
164183 success=false
165184 fi
166185 done
167186 # For source files in dev/* and mldsa/*, we enforce `Apache-2.0 OR ISC OR MIT`
168187 for file in $( git ls-files -- " *.[chsSi]" | grep " ^dev/\|^mldsa/" ) ; do
169188 # Ignore symlinks
170- if [[ ! -L $file && $( grep " SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT" $file | wc -l) == 0 ]]; then
189+ if [[ ! -L $file && $( grep " SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT" " $file " | wc -l) == 0 ]]; then
171190 gh_error " $file " " ${line:- 1} " " Missing license header error" " $file is not licensed under 'Apache-2.0 OR ISC OR MIT'"
172191 success=false
173192 fi
@@ -188,7 +207,7 @@ gh_group_end
188207
189208check-autogenerated-files ()
190209{
191- if python3 $ROOT /scripts/autogen --dry-run; then
210+ if python3 " $ROOT " /scripts/autogen --dry-run; then
192211 info " Check native auto-generated files"
193212 gh_summary_success " Check native auto-generated files"
194213 else
@@ -204,7 +223,7 @@ gh_group_end
204223
205224check-magic ()
206225{
207- if python3 $ROOT /scripts/check-magic > /dev/null; then
226+ if python3 " $ROOT " /scripts/check-magic > /dev/null; then
208227 info " Check magic constants"
209228 gh_summary_success " Check magic constants"
210229 else
224243
225244check-contracts ()
226245{
227- if python3 $ROOT /scripts/check-contracts > /dev/null; then
246+ if python3 " $ROOT " /scripts/check-contracts > /dev/null; then
228247 info " Check contracts"
229248 gh_summary_success " Check contracts"
230249 else
0 commit comments