Files
loc_az_hci/scripts/quality/lint-scripts.sh
defiQUG c39465c2bd
Some checks failed
Test / test (push) Has been cancelled
Initial commit: loc_az_hci (smom-dbis-138 excluded via .gitignore)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 09:04:46 -08:00

93 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
source ~/.bashrc
# Lint Scripts
# Run shellcheck on all shell scripts
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
SCRIPTS_DIR="$PROJECT_ROOT/scripts"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
check_shellcheck() {
if ! command -v shellcheck &> /dev/null; then
log_error "shellcheck not found"
log_info "Install shellcheck:"
log_info " Ubuntu/Debian: sudo apt-get install shellcheck"
log_info " macOS: brew install shellcheck"
log_info " Or download from: https://github.com/koalaman/shellcheck"
return 1
fi
return 0
}
lint_scripts() {
log_info "Linting all shell scripts..."
local errors=0
local warnings=0
local total=0
while IFS= read -r -d '' file; do
total=$((total + 1))
log_info "Checking: $file"
if shellcheck -x "$file" 2>&1 | tee /tmp/shellcheck_output.$$; then
log_info " ✓ No issues found"
else
local exit_code=${PIPESTATUS[0]}
if [ $exit_code -eq 0 ]; then
log_info " ✓ No issues found"
else
errors=$((errors + 1))
log_error " ✗ Issues found in $file"
fi
fi
done < <(find "$SCRIPTS_DIR" -name "*.sh" -type f -print0)
echo ""
log_info "Linting complete:"
log_info " Total scripts: $total"
log_info " Errors: $errors"
if [ $errors -eq 0 ]; then
log_info "✓ All scripts passed linting"
return 0
else
log_error "$errors script(s) have issues"
return 1
fi
}
main() {
log_info "Script Linting"
echo ""
if ! check_shellcheck; then
exit 1
fi
lint_scripts
}
main "$@"