Package: debcraft
Version: 0.5.0
Severity: minor
Tags: patch

Dear Otto,

Salsa Debcraft Issue #18 "Is shellcheck meant to be run on debian/rules?":
        https://salsa.debian.org/debian/debcraft/-/issues/18

It turns out that ShellCheck is **not** run on debian/rules.

Investigating this inspired me to make the following improvements to
debcraft-validator.sh:
  * Change misleading "debian/rules" to "debian/"
  * Capitalize as ShellCheck
  * Simplify grep commands
  * Specify dash dialect for #!/bin/sh scripts
  * Use shellcheck quiet format
  * Indicate which script(s) have validation errors
  * Fix grammar

Tested patch below.

Thank you!
Daniel Lewart
Urbana, Illinois

diff -ru a/source/src/container/debcraft-validator.sh 
b/source/src/container/debcraft-validator.sh
--- a/source/src/container/debcraft-validator.sh        2025-05-03 
20:16:25.000000000 -0500
+++ b/source/src/container/debcraft-validator.sh        2025-08-18 
00:00:00.000000000 -0500
@@ -74,23 +74,32 @@
   VALIDATION_ERRORS+=('deputy-reformat-black')
 fi
 
-log_info "Validating that all shell scripts in debian/rules pass Shellcheck..."
+log_info "Validating that all shell scripts in debian/ pass ShellCheck..."
 # End with  '|| true' to avoid emitting error codes in case no files were found
-SH_SCRIPTS="$(grep -Irnw debian/ -e '^#!.*/sh' | sort -u | cut -d ':' -f 1 || 
true)"
-BASH_SCRIPTS="$(grep -Irnw debian/ -e '^#!.*/bash' | sort -u | cut -d ':' -f 1 
|| true)"
-if [ -n "$SH_SCRIPTS" ] || [ -n "$BASH_SCRIPTS" ]
-then
-  # shellcheck disable=SC2086 # intentional expansion of arguments
-  if ! shellcheck -x --shell=sh $SH_SCRIPTS > /dev/null || ! shellcheck -x 
--shell=bash $BASH_SCRIPTS > /dev/null
+SH_SCRIPTS="$(  grep -Ilrw '^#!.*/sh'   debian/ | sort || true)"
+BASH_SCRIPTS="$(grep -Ilrw '^#!.*/bash' debian/ | sort || true)"
+
+for FILE in $SH_SCRIPTS
+do
+  if ! shellcheck -f quiet -s dash -x "$FILE"
   then
-    log_error "Shellcheck reported issues, please run it manually"
-    VALIDATION_ERRORS+=('shellcheck')
+    log_error "ShellCheck reported issues, please run it manually on $FILE"
+    [[ "${VALIDATION_ERRORS[*]}" =~ shellcheck ]] || 
VALIDATION_ERRORS+=(shellcheck)
+    # @TODO: Automatically fix by applying diff from `shellcheck -x 
--enable=all --format=diff`
+  fi
+done
 
+for FILE in $BASH_SCRIPTS
+do
+  if ! shellcheck -f quiet -s bash -x "$FILE"
+  then
+    log_error "ShellCheck reported issues, please run it manually on $FILE"
+    [[ "${VALIDATION_ERRORS[*]}" =~ shellcheck ]] || 
VALIDATION_ERRORS+=(shellcheck)
     # @TODO: Automatically fix by applying diff from `shellcheck -x 
--enable=all --format=diff`
   fi
-fi
+done
 
-# Emit non-zero exit code if there was errors
+# Emit non-zero exit code if there were errors
 if [ -n "${VALIDATION_ERRORS[*]}" ]
 then
   log_error "Failed on errors: ${VALIDATION_ERRORS[*]}"

Reply via email to