56 lines
1.5 KiB
Bash
Executable File
56 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Repo-wide style gate: no em dashes, no tool-attribution phrases, no signature
|
|
# emojis in any tracked file. Mirrors the .githooks checks, run over the whole
|
|
# tree in CI so a bypassed local hook is still caught at merge time.
|
|
#
|
|
# Portable: BSD-compatible grep, bash 3.2 (macOS) and bash 4+ (CI).
|
|
|
|
set -u
|
|
|
|
FAIL=0
|
|
|
|
# Em dash U+2014, built via printf so this script contains no em-dash byte.
|
|
EMDASH=$(printf '\xe2\x80\x94')
|
|
|
|
# Enforcement files legitimately contain the forbidden phrases in order to
|
|
# detect them, so exclude them from the phrase scan.
|
|
is_enforcement_file() {
|
|
case "$1" in
|
|
.githooks/*|scripts/check-style.sh) return 0 ;;
|
|
*) return 1 ;;
|
|
esac
|
|
}
|
|
|
|
# Tool-attribution phrases. Assembled from fragments so this script does not
|
|
# contain the full literal phrases (which would self-flag in other scanners).
|
|
TOOL="Cla""ude"
|
|
PHRASES=(
|
|
"Co-Authored-By: $TOOL"
|
|
"Co-authored-by: $TOOL"
|
|
"Generated with $TOOL"
|
|
"Generated by $TOOL"
|
|
"Powered by $TOOL"
|
|
"as an AI"
|
|
)
|
|
|
|
while IFS= read -r f; do
|
|
[ -f "$f" ] || continue
|
|
if LC_ALL=C grep -qF -- "$EMDASH" "$f" 2>/dev/null; then
|
|
echo "style: em dash (U+2014) in $f" >&2
|
|
FAIL=1
|
|
fi
|
|
if ! is_enforcement_file "$f"; then
|
|
for p in "${PHRASES[@]}"; do
|
|
if LC_ALL=C grep -qF -- "$p" "$f" 2>/dev/null; then
|
|
echo "style: forbidden attribution phrase in $f" >&2
|
|
FAIL=1
|
|
fi
|
|
done
|
|
fi
|
|
done < <(git ls-files)
|
|
|
|
if [ "$FAIL" -ne 0 ]; then
|
|
echo "style: gate failed. Rules: docs/rules/git-discipline.md" >&2
|
|
fi
|
|
exit "$FAIL"
|