@@ -231,19 +231,15 @@ run_shellcheck() {
231
231
local file=" $1 "
232
232
echo " Running shellcheck on $file "
233
233
234
- # Try to auto-fix issues
235
234
local diff_output
236
235
diff_output=$( shellcheck -f diff " $file " -e SC2154 -e SC1091 -e SC1090 -e SC2148 -o require-variable-braces -P " scripts" 2>&1 )
237
236
238
- if [[ " $diff_output " == * " Issues were detected, but none were auto-fixable" * ]]; then
239
- echo -e " ${RED} shellcheck failed on $file ${NO_COLOR} "
240
- echo " $file " >> " ${SHELLCHECK_FAILED_FILE} "
241
- return 1
242
- elif echo " $diff_output " | git apply --allow-empty; then
237
+ if [[ -n " $diff_output " && " $diff_output " != * " Issues were detected, but none were auto-fixable" * ]]; then
238
+ echo " $diff_output " | git apply
243
239
echo " Applied auto-fixes for $file "
244
- else
240
+ elif [[ " $diff_output " == * " Issues were detected, but none were auto-fixable " * ]] ; then
245
241
echo -e " ${RED} shellcheck failed on $file ${NO_COLOR} "
246
- echo " $file " >> " ${SHELLCHECK_FAILED_FILE} "
242
+ shellcheck --color=always -x " $file " -e SC2154 -e SC1091 -e SC1090 -e SC2148 -o require-variable-braces -P " scripts "
247
243
return 1
248
244
fi
249
245
}
@@ -252,32 +248,14 @@ run_shellcheck() {
252
248
export -f run_shellcheck
253
249
254
250
start_shellcheck () {
255
- # Create temporary file to track failed files
256
- local failed_file
257
- failed_file=$( mktemp)
258
- export SHELLCHECK_FAILED_FILE=" $failed_file "
259
-
260
251
# shellcheck disable=SC2016
261
252
{
262
253
find scripts -type f -name " *.sh"
263
254
find scripts/dev/contexts -type f | grep -v private-context
264
255
find scripts/funcs -type f
265
256
find public/architectures -type f -name " *.sh"
266
257
find docs/ -type f -name " *.sh"
267
- } | xargs -I {} -P 20 bash -c ' run_shellcheck "$1" || true' _ {}
268
-
269
- # Show summary of failed files
270
- if [[ -s " $failed_file " ]]; then
271
- echo -e " \n${RED} Shellcheck failed on the following files:${NO_COLOR} "
272
- while read -r file; do
273
- echo -e " ${RED} ✗${NO_COLOR} $file "
274
- done < " $failed_file "
275
- echo -e " \n${RED} Total: $( wc -l < " $failed_file " ) file(s) failed shellcheck${NO_COLOR} "
276
- rm -f " $failed_file "
277
- exit 1
278
- fi
279
-
280
- rm -f " $failed_file "
258
+ } | xargs -I {} -P 20 bash -c ' run_shellcheck "$1"' _ {}
281
259
}
282
260
283
261
cmd=${1:- " pre-commit" }
0 commit comments