Files
lgp-admin-plus-api/scripts/lint.sh
LQ bcf54c2727 初始化
缺陷:主题配色需要优化整体的同风格
2026-08-14 23:21:21 +08:00

42 lines
1023 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 语法检查 + 行尾规整
#
# 从 Windows 侧的 UNC 路径写文件会带 CRLFPHP 能跑但和仓库里其余 LF 文件混排,
# diff 会整片变红。这里统一转成 LF 再 php -l。
#
# 用法bash scripts/lint.sh [目录或文件 ...] 不带参数则检查 app/ routes/ config/
set -uo pipefail
cd "$(diname "$0")/.." || exit 1
TARGETS=("$@")
if [ ${#TARGETS[@]} -eq 0 ]; then
TARGETS=(app routes config database)
fi
mapfile -t FILES < <(find "${TARGETS[@]}" -type f -name '*.php' 2>/dev/null | sort)
if [ ${#FILES[@]} -eq 0 ]; then
echo "no php files under: ${TARGETS[*]}"
exit 0
fi
CRLF_FIXED=0
for f in "${FILES[@]}"; do
if grep -qU $'\r' "$f" 2>/dev/null; then
perl -pi -e 's/\r\n/\n/' "$f"
CRLF_FIXED=$((CRLF_FIXED + 1))
fi
done
FAILED=0
for f in "${FILES[@]}"; do
if ! out=$(php -l "$f" 2>&1); then
echo "$out"
FAILED=$((FAILED + 1))
fi
done
echo "checked=${#FILES[@]} crlf_fixed=${CRLF_FIXED} syntax_errors=${FAILED}"
[ "$FAILED" -eq 0 ]