Mirror the shared Swift rules canon (rules-swift, commit 4ebb892) into docs/rules-swift/ as a read-only reference alongside the repo's tailored docs/rules/. PROVENANCE.md records the source, commit, and what was included or excluded; the upstream repo's own VCS, CI, and lint tooling is omitted as machinery rather than rule content. Exclude the vendored tree from the style gate (scripts/check-style.sh) and the pre-commit hook: the canon's enforcement docs quote the forbidden attribution phrases to define them, the same reason the repo's own enforcement files are already excluded.
76 lines
2.1 KiB
Bash
Executable File
76 lines
2.1 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
|
|
}
|
|
|
|
is_vendored_fixture() {
|
|
case "$1" in
|
|
Tests/Fixtures/acme/*|Tests/Fixtures/real-yaml/*) return 0 ;;
|
|
# Vendored upstream rules canon (mirror of the rules-swift repo). Its own
|
|
# enforcement docs legitimately quote the forbidden attribution phrases, so
|
|
# the whole vendored tree is excluded from the style scan, exactly like the
|
|
# repo's own enforcement files. Provenance: docs/rules-swift/PROVENANCE.md.
|
|
docs/rules-swift/*) 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 is_vendored_fixture "$f"; then
|
|
continue
|
|
fi
|
|
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
|
|
|
|
if ! bash scripts/check-roadmap.sh; then
|
|
FAIL=1
|
|
fi
|
|
|
|
exit "$FAIL"
|