/srv/storage/ansible/tools/unicode_scan.sh
#!/bin/bash
set -e
TARGET_DIR=${1:-.}
echo "[*] Scanning for invisible Unicode..."
# 除外
EXCLUDES="--exclude-dir=.git --exclude=*.vault --exclude=*.retry"
if grep -P -nR $EXCLUDES \
"[\x{200B}-\x{200F}\x{202A}-\x{202E}\x{2060}\x{FEFF}]" \
"$TARGET_DIR"
then
echo "[!] Invisible Unicode detected"
exit 1
else
echo "[OK] Clean"
fi
chmod +x tools/unicode_scan.sh
例:site.ymlの最初に追加
- name: Pre-check (Unicode scan)
hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Run unicode scan
command: ./tools/unicode_scan.sh .
args:
chdir: "{{ playbook_dir }}"
👉 これで:
.git/hooks/pre-commit
#!/bin/bash
./tools/unicode_scan.sh .