Skip to content

Commit 6bf24e9

Browse files
committed
fix shellcheck and auto fix
1 parent b63152e commit 6bf24e9

File tree

1 file changed

+5
-27
lines changed

1 file changed

+5
-27
lines changed

.githooks/pre-commit

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,15 @@ run_shellcheck() {
231231
local file="$1"
232232
echo "Running shellcheck on $file"
233233

234-
# Try to auto-fix issues
235234
local diff_output
236235
diff_output=$(shellcheck -f diff "$file" -e SC2154 -e SC1091 -e SC1090 -e SC2148 -o require-variable-braces -P "scripts" 2>&1)
237236

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
243239
echo "Applied auto-fixes for $file"
244-
else
240+
elif [[ "$diff_output" == *"Issues were detected, but none were auto-fixable"* ]]; then
245241
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"
247243
return 1
248244
fi
249245
}
@@ -252,32 +248,14 @@ run_shellcheck() {
252248
export -f run_shellcheck
253249

254250
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-
260251
# shellcheck disable=SC2016
261252
{
262253
find scripts -type f -name "*.sh"
263254
find scripts/dev/contexts -type f | grep -v private-context
264255
find scripts/funcs -type f
265256
find public/architectures -type f -name "*.sh"
266257
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"' _ {}
281259
}
282260

283261
cmd=${1:-"pre-commit"}

0 commit comments

Comments
 (0)