Files
dacli/scripts/check_clean_comments.sh
T
2026-07-17 12:20:48 +08:00

59 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# 检查 dacli/src/** 内违规注释:
# - BS-* / BS-new* / R\d+ / Round\d+
# - jxcj / workSystem / developSystem / tds
# - v0\.\d+\+? 版本号
# - ssw-...-biz / ssw-common 跨语言反向引用
# 命中即报错 (含具体文件:行号).
set -uo pipefail
DACLI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SRC_DIR="$DACLI_DIR/src"
PATTERNS=(
'BS-[a-zA-Z]*[0-9]'
'R[0-9]+[a-z]*\b'
'Round[0-9]+'
'\b(jxcj|workSystem|developSystem|tds)\b'
'v0\.[0-9]+[a-z]*\+'
'ssw-[a-z]+-(biz|common)'
)
# 白名单文件 (必须保留 source 引用)
WHITELIST=(
"_anti_patterns.ts"
)
EXIT_CODE=0
for pattern in "${PATTERNS[@]}"; do
while IFS=: read -r file line content; do
if [ -z "$file" ]; then continue; fi
# Check whitelist
basename_file=$(basename "$file")
skip=0
for wl in "${WHITELIST[@]}"; do
if [ "$basename_file" = "$wl" ]; then skip=1; break; fi
done
[ $skip -eq 1 ] && continue
# Only flag comment lines (//, *, or /* ... */)
trimmed=$(echo "$content" | sed 's/^[[:space:]]*//')
if ! echo "$trimmed" | grep -qE '^(//|/\*|\*)'; then
continue # skip code/string lines, only check comments
fi
echo "VIOLATION: $file:$line"
echo " pattern: /$pattern/"
echo " content: $content"
EXIT_CODE=1
done < <(grep -rnE "$pattern" "$SRC_DIR" --include="*.ts" --include="*.tsx" 2>/dev/null || true)
done
if [ $EXIT_CODE -eq 0 ]; then
echo "OK: no violations found"
fi
exit $EXIT_CODE