style: convert tabs to spaces in shell_check.sh

This commit is contained in:
Krzysztof Rudnicki 2025-11-16 21:00:22 +01:00
parent 4256df1d15
commit e7dd2e4c6d

View File

@ -38,7 +38,7 @@ log_error() {
} }
usage() { usage() {
cat <<EOF cat << EOF
Usage: $(basename "$0") [options] Usage: $(basename "$0") [options]
Options: Options:
@ -93,7 +93,7 @@ if [[ ! -d $ROOT_DIR ]]; then
exit 2 exit 2
fi fi
is_cmd() { command -v "$1" >/dev/null 2>&1; } is_cmd() { command -v "$1" > /dev/null 2>&1; }
is_arch() { is_cmd pacman; } is_arch() { is_cmd pacman; }
have_aur_helper() { is_cmd yay || is_cmd paru; } have_aur_helper() { is_cmd yay || is_cmd paru; }
@ -136,7 +136,7 @@ install_linters() {
# checkbashisms may be in repos or AUR; try pacman first, then AUR helper # checkbashisms may be in repos or AUR; try pacman first, then AUR helper
if ! is_cmd checkbashisms; then if ! is_cmd checkbashisms; then
if is_arch; then if is_arch; then
if ! sudo pacman -S --needed --noconfirm checkbashisms 2>/dev/null; then if ! sudo pacman -S --needed --noconfirm checkbashisms 2> /dev/null; then
if have_aur_helper; then if have_aur_helper; then
log_info "Installing checkbashisms from AUR (requires yay/paru)..." log_info "Installing checkbashisms from AUR (requires yay/paru)..."
if is_cmd yay; then yay -S --noconfirm checkbashisms || true; fi if is_cmd yay; then yay -S --noconfirm checkbashisms || true; fi
@ -182,7 +182,7 @@ discover_shell_files() {
local -a all local -a all
all=() all=()
if git -C "$base" rev-parse --is-inside-work-tree >/dev/null 2>&1; then if git -C "$base" rev-parse --is-inside-work-tree > /dev/null 2>&1; then
while IFS= read -r -d '' f; do all+=("$f"); done < <(git -C "$base" ls-files -z) while IFS= read -r -d '' f; do all+=("$f"); done < <(git -C "$base" ls-files -z)
while IFS= read -r -d '' f; do all+=("$f"); done < <(git -C "$base" ls-files --others --exclude-standard -z) while IFS= read -r -d '' f; do all+=("$f"); done < <(git -C "$base" ls-files --others --exclude-standard -z)
else else
@ -215,7 +215,7 @@ discover_shell_files() {
# Check shebang # Check shebang
local first local first
first=$(head -n 1 -- "$abs" 2>/dev/null || true) first=$(head -n 1 -- "$abs" 2> /dev/null || true)
if [[ $first =~ ^#! && $first =~ (ba|z|d|k)?sh ]]; then if [[ $first =~ ^#! && $first =~ (ba|z|d|k)?sh ]]; then
shells+=("$rel") shells+=("$rel")
continue continue
@ -230,38 +230,38 @@ discover_shell_files() {
done done
# write lists # write lists
: >"$REL_FILES_Z" : > "$REL_FILES_Z"
: >"$ABS_FILES_Z" : > "$ABS_FILES_Z"
for rel in "${shells[@]}"; do for rel in "${shells[@]}"; do
printf '%s\0' "$rel" >>"$REL_FILES_Z" printf '%s\0' "$rel" >> "$REL_FILES_Z"
printf '%s\0' "$base/$rel" >>"$ABS_FILES_Z" printf '%s\0' "$base/$rel" >> "$ABS_FILES_Z"
done done
} }
print_file_list() { print_file_list() {
local count local count
count=$(tr -cd '\0' <"$REL_FILES_Z" | wc -c) count=$(tr -cd '\0' < "$REL_FILES_Z" | wc -c)
log_info "Discovered $count shell file(s) under $ROOT_DIR" log_info "Discovered $count shell file(s) under $ROOT_DIR"
if [[ $VERBOSE == "true" ]]; then if [[ $VERBOSE == "true" ]]; then
tr '\0' '\n' <"$REL_FILES_Z" | sed 's/^/ - /' tr '\0' '\n' < "$REL_FILES_Z" | sed 's/^/ - /'
fi fi
} }
run_linters() { run_linters() {
local issues=0 local issues=0
local count local count
count=$(tr -cd '\0' <"$ABS_FILES_Z" | wc -c) count=$(tr -cd '\0' < "$ABS_FILES_Z" | wc -c)
if [[ $count -eq 0 ]]; then if [[ $count -eq 0 ]]; then
log_warn "No shell files found to lint." log_warn "No shell files found to lint."
return 0 return 0
fi fi
mapfile -d '' -t FILES <"$ABS_FILES_Z" mapfile -d '' -t FILES < "$ABS_FILES_Z"
log_info "Running shellcheck..." log_info "Running shellcheck..."
local sc_out="$TMPDIR/shellcheck.txt" local sc_out="$TMPDIR/shellcheck.txt"
if is_cmd shellcheck; then if is_cmd shellcheck; then
if ! shellcheck -x -S style "${FILES[@]}" >"$sc_out" 2>&1; then if ! shellcheck -x -S style "${FILES[@]}" > "$sc_out" 2>&1; then
issues=$((issues + 1)) issues=$((issues + 1))
fi fi
else else
@ -271,7 +271,7 @@ run_linters() {
log_info "Running shfmt (diff mode)..." log_info "Running shfmt (diff mode)..."
local shfmt_out="$TMPDIR/shfmt.diff" local shfmt_out="$TMPDIR/shfmt.diff"
if is_cmd shfmt; then if is_cmd shfmt; then
if ! shfmt -d -i 2 -ci -sr -s "${FILES[@]}" >"$shfmt_out" 2>&1; then if ! shfmt -d -i 2 -ci -sr -s "${FILES[@]}" > "$shfmt_out" 2>&1; then
# shfmt returns non-zero when diff exists # shfmt returns non-zero when diff exists
issues=$((issues + 1)) issues=$((issues + 1))
fi fi
@ -289,7 +289,7 @@ run_linters() {
CBI_FILES=() CBI_FILES=()
for f in "${FILES[@]}"; do for f in "${FILES[@]}"; do
local first local first
first=$(head -n 1 -- "$f" 2>/dev/null || true) first=$(head -n 1 -- "$f" 2> /dev/null || true)
if [[ $first =~ bash || $first =~ zsh ]]; then if [[ $first =~ bash || $first =~ zsh ]]; then
continue continue
fi fi
@ -297,9 +297,9 @@ run_linters() {
done done
if [[ ${#CBI_FILES[@]} -gt 0 ]]; then if [[ ${#CBI_FILES[@]} -gt 0 ]]; then
# checkbashisms exits 0 if OK, 1 if issues, other codes for tool warnings # checkbashisms exits 0 if OK, 1 if issues, other codes for tool warnings
checkbashisms "${CBI_FILES[@]}" >"$cbi_out" 2>&1 checkbashisms "${CBI_FILES[@]}" > "$cbi_out" 2>&1
else else
: >"$cbi_out" : > "$cbi_out"
fi fi
cbi_status=$? cbi_status=$?
if [[ $cbi_status -eq 1 ]]; then if [[ $cbi_status -eq 1 ]]; then
@ -323,7 +323,7 @@ run_linters() {
SH_FILES=() SH_FILES=()
for f in "${FILES[@]}"; do for f in "${FILES[@]}"; do
local first local first
first=$(head -n 1 -- "$f" 2>/dev/null || true) first=$(head -n 1 -- "$f" 2> /dev/null || true)
if [[ $first =~ bash ]]; then if [[ $first =~ bash ]]; then
BASH_FILES+=("$f") BASH_FILES+=("$f")
elif [[ $first =~ zsh ]]; then elif [[ $first =~ zsh ]]; then
@ -334,23 +334,23 @@ run_linters() {
done done
if [[ ${#BASH_FILES[@]} -gt 0 ]] && is_cmd bash; then if [[ ${#BASH_FILES[@]} -gt 0 ]] && is_cmd bash; then
if ! bash -n "${BASH_FILES[@]}" 2>"$bash_out"; then if ! bash -n "${BASH_FILES[@]}" 2> "$bash_out"; then
issues=$((issues + 1)) issues=$((issues + 1))
fi fi
fi fi
if [[ ${#ZSH_FILES[@]} -gt 0 ]] && is_cmd zsh; then if [[ ${#ZSH_FILES[@]} -gt 0 ]] && is_cmd zsh; then
if ! zsh -n "${ZSH_FILES[@]}" 2>"$zsh_out"; then if ! zsh -n "${ZSH_FILES[@]}" 2> "$zsh_out"; then
issues=$((issues + 1)) issues=$((issues + 1))
fi fi
fi fi
# prefer dash if present for /bin/sh style # prefer dash if present for /bin/sh style
if [[ ${#SH_FILES[@]} -gt 0 ]]; then if [[ ${#SH_FILES[@]} -gt 0 ]]; then
if is_cmd dash; then if is_cmd dash; then
if ! dash -n "${SH_FILES[@]}" 2>"$sh_out"; then if ! dash -n "${SH_FILES[@]}" 2> "$sh_out"; then
issues=$((issues + 1)) issues=$((issues + 1))
fi fi
elif is_cmd sh; then elif is_cmd sh; then
if ! sh -n "${SH_FILES[@]}" 2>"$sh_out"; then if ! sh -n "${SH_FILES[@]}" 2> "$sh_out"; then
issues=$((issues + 1)) issues=$((issues + 1))
fi fi
fi fi