mirror of
https://github.com/kuhyx/scripts.git
synced 2026-07-04 15:03:09 +02:00
style: convert tabs to spaces in shell_check.sh
This commit is contained in:
parent
4256df1d15
commit
e7dd2e4c6d
@ -26,19 +26,19 @@ LIST_ONLY="false"
|
|||||||
VERBOSE="false"
|
VERBOSE="false"
|
||||||
|
|
||||||
log_info() {
|
log_info() {
|
||||||
printf '\033[1;34m[INFO]\033[0m %s\n' "$*"
|
printf '\033[1;34m[INFO]\033[0m %s\n' "$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
log_warn() {
|
log_warn() {
|
||||||
printf '\033[1;33m[WARN]\033[0m %s\n' "$*"
|
printf '\033[1;33m[WARN]\033[0m %s\n' "$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
log_error() {
|
log_error() {
|
||||||
printf '\033[1;31m[ERROR]\033[0m %s\n' "$*" >&2
|
printf '\033[1;31m[ERROR]\033[0m %s\n' "$*" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat << EOF
|
||||||
Usage: $(basename "$0") [options]
|
Usage: $(basename "$0") [options]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
@ -55,120 +55,120 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--path)
|
--path)
|
||||||
ROOT_DIR="$2"
|
ROOT_DIR="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--skip-install)
|
--skip-install)
|
||||||
SKIP_INSTALL="true"
|
SKIP_INSTALL="true"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--install-only)
|
--install-only)
|
||||||
INSTALL_ONLY="true"
|
INSTALL_ONLY="true"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--list-only)
|
--list-only)
|
||||||
LIST_ONLY="true"
|
LIST_ONLY="true"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--verbose)
|
--verbose)
|
||||||
VERBOSE="true"
|
VERBOSE="true"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-h | --help)
|
-h | --help)
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
log_error "Unknown argument: $1"
|
log_error "Unknown argument: $1"
|
||||||
usage
|
usage
|
||||||
exit 2
|
exit 2
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ ! -d $ROOT_DIR ]]; then
|
if [[ ! -d $ROOT_DIR ]]; then
|
||||||
log_error "Path not found: $ROOT_DIR"
|
log_error "Path not found: $ROOT_DIR"
|
||||||
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; }
|
||||||
|
|
||||||
install_if_missing() {
|
install_if_missing() {
|
||||||
local pkg cmd
|
local pkg cmd
|
||||||
pkg="$1"
|
pkg="$1"
|
||||||
cmd="$2"
|
cmd="$2"
|
||||||
if is_cmd "$cmd"; then
|
if is_cmd "$cmd"; then
|
||||||
[[ $VERBOSE == "true" ]] && log_info "Found $cmd"
|
[[ $VERBOSE == "true" ]] && log_info "Found $cmd"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $SKIP_INSTALL == "true" ]]; then
|
if [[ $SKIP_INSTALL == "true" ]]; then
|
||||||
log_warn "Skipping install of $pkg ($cmd not found)"
|
log_warn "Skipping install of $pkg ($cmd not found)"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if is_arch; then
|
if is_arch; then
|
||||||
log_info "Installing $pkg via pacman..."
|
log_info "Installing $pkg via pacman..."
|
||||||
if ! sudo pacman -S --needed --noconfirm "$pkg"; then
|
if ! sudo pacman -S --needed --noconfirm "$pkg"; then
|
||||||
log_warn "Failed to install $pkg via pacman."
|
log_warn "Failed to install $pkg via pacman."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
log_warn "Non-Arch system detected. Please install '$pkg' manually."
|
log_warn "Non-Arch system detected. Please install '$pkg' manually."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_linters() {
|
install_linters() {
|
||||||
local ok=0
|
local ok=0
|
||||||
|
|
||||||
# Core linters
|
# Core linters
|
||||||
install_if_missing shellcheck shellcheck || ok=1
|
install_if_missing shellcheck shellcheck || ok=1
|
||||||
install_if_missing shfmt shfmt || ok=1
|
install_if_missing shfmt shfmt || ok=1
|
||||||
|
|
||||||
# Optional linters (best-effort)
|
# Optional linters (best-effort)
|
||||||
# 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
|
||||||
if is_cmd paru; then paru -S --noconfirm checkbashisms || true; fi
|
if is_cmd paru; then paru -S --noconfirm checkbashisms || true; fi
|
||||||
else
|
else
|
||||||
log_warn "checkbashisms not installed (no AUR helper)."
|
log_warn "checkbashisms not installed (no AUR helper)."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# bashate (python-based), typically available as python-bashate in AUR
|
# bashate (python-based), typically available as python-bashate in AUR
|
||||||
if ! is_cmd bashate; then
|
if ! is_cmd bashate; then
|
||||||
if is_arch && have_aur_helper; then
|
if is_arch && have_aur_helper; then
|
||||||
log_info "Installing bashate from AUR (requires yay/paru)..."
|
log_info "Installing bashate from AUR (requires yay/paru)..."
|
||||||
if is_cmd yay; then yay -S --noconfirm python-bashate || true; fi
|
if is_cmd yay; then yay -S --noconfirm python-bashate || true; fi
|
||||||
if is_cmd paru; then paru -S --noconfirm python-bashate || true; fi
|
if is_cmd paru; then paru -S --noconfirm python-bashate || true; fi
|
||||||
else
|
else
|
||||||
# Try pip if user has it and wants to
|
# Try pip if user has it and wants to
|
||||||
if is_cmd pipx; then
|
if is_cmd pipx; then
|
||||||
log_info "Installing bashate via pipx..."
|
log_info "Installing bashate via pipx..."
|
||||||
pipx install bashate || true
|
pipx install bashate || true
|
||||||
elif is_cmd pip3; then
|
elif is_cmd pip3; then
|
||||||
log_info "Installing bashate via pip (user)..."
|
log_info "Installing bashate via pip (user)..."
|
||||||
pip3 install --user bashate || true
|
pip3 install --user bashate || true
|
||||||
else
|
else
|
||||||
log_warn "bashate not installed (no AUR helper or pip available)."
|
log_warn "bashate not installed (no AUR helper or pip available)."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return "$ok"
|
return "$ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
TMPDIR=$(mktemp -d)
|
TMPDIR=$(mktemp -d)
|
||||||
@ -178,255 +178,255 @@ ABS_FILES_Z="$TMPDIR/files_abs.zlist"
|
|||||||
REL_FILES_Z="$TMPDIR/files_rel.zlist"
|
REL_FILES_Z="$TMPDIR/files_rel.zlist"
|
||||||
|
|
||||||
discover_shell_files() {
|
discover_shell_files() {
|
||||||
local base="$1"
|
local base="$1"
|
||||||
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
|
||||||
while IFS= read -r -d '' f; do
|
while IFS= read -r -d '' f; do
|
||||||
# trim leading ./ to keep consistent style with git paths
|
# trim leading ./ to keep consistent style with git paths
|
||||||
f="${f#./}"
|
f="${f#./}"
|
||||||
f="${f#"${base}"/}"
|
f="${f#"${base}"/}"
|
||||||
all+=("$f")
|
all+=("$f")
|
||||||
done < <(find "$base" -type f -print0)
|
done < <(find "$base" -type f -print0)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local -a shells
|
local -a shells
|
||||||
shells=()
|
shells=()
|
||||||
|
|
||||||
for rel in "${all[@]}"; do
|
for rel in "${all[@]}"; do
|
||||||
# skip binary-ish or huge files quickly by extension heuristic
|
# skip binary-ish or huge files quickly by extension heuristic
|
||||||
case "$rel" in
|
case "$rel" in
|
||||||
*.png | *.jpg | *.jpeg | *.gif | *.ico | *.pdf | *.svg | *.zip | *.tar | *.gz | *.xz | *.7z | *.so | *.o | *.bin)
|
*.png | *.jpg | *.jpeg | *.gif | *.ico | *.pdf | *.svg | *.zip | *.tar | *.gz | *.xz | *.7z | *.so | *.o | *.bin)
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
local abs="$base/$rel"
|
local abs="$base/$rel"
|
||||||
[[ -f $abs && -r $abs ]] || continue
|
[[ -f $abs && -r $abs ]] || continue
|
||||||
|
|
||||||
if [[ $rel == *.sh || $rel == *.bash || $rel == *.zsh ]]; then
|
if [[ $rel == *.sh || $rel == *.bash || $rel == *.zsh ]]; then
|
||||||
shells+=("$rel")
|
shells+=("$rel")
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Also catch executable files with shell shebang even without extension
|
# Also catch executable files with shell shebang even without extension
|
||||||
if [[ -x $abs ]]; then
|
if [[ -x $abs ]]; then
|
||||||
if [[ $first =~ ^#! && $first =~ (ba|z|d|k)?sh ]]; then
|
if [[ $first =~ ^#! && $first =~ (ba|z|d|k)?sh ]]; then
|
||||||
shells+=("$rel")
|
shells+=("$rel")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
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
|
||||||
log_warn "shellcheck not found; skipping"
|
log_warn "shellcheck not found; skipping"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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
|
||||||
else
|
else
|
||||||
log_warn "shfmt not found; skipping"
|
log_warn "shfmt not found; skipping"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_info "Running checkbashisms (optional)..."
|
log_info "Running checkbashisms (optional)..."
|
||||||
local cbi_out="$TMPDIR/checkbashisms.txt"
|
local cbi_out="$TMPDIR/checkbashisms.txt"
|
||||||
local cbi_status=0
|
local cbi_status=0
|
||||||
if is_cmd checkbashisms; then
|
if is_cmd checkbashisms; then
|
||||||
# Only run checkbashisms on scripts that are intended for /bin/sh (or unspecified),
|
# Only run checkbashisms on scripts that are intended for /bin/sh (or unspecified),
|
||||||
# skip explicit bash/zsh scripts to avoid false positives.
|
# skip explicit bash/zsh scripts to avoid false positives.
|
||||||
local -a CBI_FILES
|
local -a CBI_FILES
|
||||||
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
|
||||||
CBI_FILES+=("$f")
|
CBI_FILES+=("$f")
|
||||||
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
|
||||||
issues=$((issues + 1))
|
issues=$((issues + 1))
|
||||||
elif [[ $cbi_status -ne 0 ]]; then
|
elif [[ $cbi_status -ne 0 ]]; then
|
||||||
log_warn "checkbashisms exited with status $cbi_status (treated as warning)"
|
log_warn "checkbashisms exited with status $cbi_status (treated as warning)"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
log_warn "checkbashisms not found; skipping"
|
log_warn "checkbashisms not found; skipping"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_info "Running bash/zsh/sh syntax checks (-n)..."
|
log_info "Running bash/zsh/sh syntax checks (-n)..."
|
||||||
local bash_out="$TMPDIR/bash_syntax.txt"
|
local bash_out="$TMPDIR/bash_syntax.txt"
|
||||||
local zsh_out="$TMPDIR/zsh_syntax.txt"
|
local zsh_out="$TMPDIR/zsh_syntax.txt"
|
||||||
local sh_out="$TMPDIR/sh_syntax.txt"
|
local sh_out="$TMPDIR/sh_syntax.txt"
|
||||||
|
|
||||||
# Partition files by shebang for better accuracy
|
# Partition files by shebang for better accuracy
|
||||||
local -a BASH_FILES ZSH_FILES SH_FILES
|
local -a BASH_FILES ZSH_FILES SH_FILES
|
||||||
BASH_FILES=()
|
BASH_FILES=()
|
||||||
ZSH_FILES=()
|
ZSH_FILES=()
|
||||||
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
|
||||||
ZSH_FILES+=("$f")
|
ZSH_FILES+=("$f")
|
||||||
else
|
else
|
||||||
SH_FILES+=("$f")
|
SH_FILES+=("$f")
|
||||||
fi
|
fi
|
||||||
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
log_info "========== Shell Lint Report =========="
|
log_info "========== Shell Lint Report =========="
|
||||||
|
|
||||||
if [[ -s $sc_out ]]; then
|
if [[ -s $sc_out ]]; then
|
||||||
printf '\n\033[1m-- shellcheck --\033[0m\n'
|
printf '\n\033[1m-- shellcheck --\033[0m\n'
|
||||||
cat "$sc_out"
|
cat "$sc_out"
|
||||||
else
|
else
|
||||||
printf '\n\033[1;32m-- shellcheck: PASS (no issues) --\033[0m\n'
|
printf '\n\033[1;32m-- shellcheck: PASS (no issues) --\033[0m\n'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -s $shfmt_out ]]; then
|
if [[ -s $shfmt_out ]]; then
|
||||||
printf '\n\033[1m-- shfmt (diffs found) --\033[0m\n'
|
printf '\n\033[1m-- shfmt (diffs found) --\033[0m\n'
|
||||||
cat "$shfmt_out"
|
cat "$shfmt_out"
|
||||||
else
|
else
|
||||||
printf '\n\033[1;32m-- shfmt: PASS (formatted) --\033[0m\n'
|
printf '\n\033[1;32m-- shfmt: PASS (formatted) --\033[0m\n'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -s $cbi_out ]]; then
|
if [[ -s $cbi_out ]]; then
|
||||||
printf '\n\033[1m-- checkbashisms --\033[0m\n'
|
printf '\n\033[1m-- checkbashisms --\033[0m\n'
|
||||||
cat "$cbi_out"
|
cat "$cbi_out"
|
||||||
else
|
else
|
||||||
printf '\n\033[1;32m-- checkbashisms: PASS (or skipped) --\033[0m\n'
|
printf '\n\033[1;32m-- checkbashisms: PASS (or skipped) --\033[0m\n'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -s $bash_out ]]; then
|
if [[ -s $bash_out ]]; then
|
||||||
printf '\n\033[1m-- bash -n (syntax) --\033[0m\n'
|
printf '\n\033[1m-- bash -n (syntax) --\033[0m\n'
|
||||||
cat "$bash_out"
|
cat "$bash_out"
|
||||||
else
|
else
|
||||||
printf '\n\033[1;32m-- bash -n: PASS (or none) --\033[0m\n'
|
printf '\n\033[1;32m-- bash -n: PASS (or none) --\033[0m\n'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -s $zsh_out ]]; then
|
if [[ -s $zsh_out ]]; then
|
||||||
printf '\n\033[1m-- zsh -n (syntax) --\033[0m\n'
|
printf '\n\033[1m-- zsh -n (syntax) --\033[0m\n'
|
||||||
cat "$zsh_out"
|
cat "$zsh_out"
|
||||||
else
|
else
|
||||||
printf '\n\033[1;32m-- zsh -n: PASS (or none) --\033[0m\n'
|
printf '\n\033[1;32m-- zsh -n: PASS (or none) --\033[0m\n'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -s $sh_out ]]; then
|
if [[ -s $sh_out ]]; then
|
||||||
printf '\n\033[1m-- sh/dash -n (syntax) --\033[0m\n'
|
printf '\n\033[1m-- sh/dash -n (syntax) --\033[0m\n'
|
||||||
cat "$sh_out"
|
cat "$sh_out"
|
||||||
else
|
else
|
||||||
printf '\n\033[1;32m-- sh/dash -n: PASS (or none) --\033[0m\n'
|
printf '\n\033[1;32m-- sh/dash -n: PASS (or none) --\033[0m\n'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
if [[ $issues -gt 0 ]]; then
|
if [[ $issues -gt 0 ]]; then
|
||||||
log_error "Linting completed with $issues tool(s) reporting issues."
|
log_error "Linting completed with $issues tool(s) reporting issues."
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
log_info "All checks passed."
|
log_info "All checks passed."
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
if [[ $INSTALL_ONLY == "true" ]]; then
|
if [[ $INSTALL_ONLY == "true" ]]; then
|
||||||
install_linters
|
install_linters
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Only attempt installs if not list-only
|
# Only attempt installs if not list-only
|
||||||
if [[ $LIST_ONLY != "true" ]]; then
|
if [[ $LIST_ONLY != "true" ]]; then
|
||||||
install_linters || true
|
install_linters || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
discover_shell_files "$ROOT_DIR"
|
discover_shell_files "$ROOT_DIR"
|
||||||
print_file_list
|
print_file_list
|
||||||
|
|
||||||
if [[ $LIST_ONLY == "true" ]]; then
|
if [[ $LIST_ONLY == "true" ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
run_linters
|
run_linters
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user