PureXML/third_party/rules-swift/scripts/check-namespacing.sh
Mihaela Mihaljevic c7ef8abfd9 chore(rules): pin rules-swift corpus, add gates and CI; drop redundant docs/rules mirror
Adopt the rules-swift pin-and-codify strategy in snapshot mode (third_party/rules-swift
@97dc70f + sha256), add codified gates, a conformance audit ledger, and
.github/workflows/rules-swift.yml (corpus-pin integrity required, full gate report mode).
Remove the docs/rules mirror it supersedes (repo-specific files kept under docs/). Style
and leak gates exclude the vendored corpus.
2026-06-30 14:02:40 +02:00

30 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# Namespacing gate: one non-private top-level type per file.
# Enforces the "One non-private type per file (mandatory)" rule in code-style.md.
# Runs on every commit (.githooks/pre-commit) and in CI (.github/workflows/leak-gate.yml).
# A file declaring more than one public/package/internal top-level type is a violation;
# mark helper types private/fileprivate so they drop out, or split the file.
set -eu
ROOT=$(cd "$(dirname "$0")/.." && pwd)
SCAN="$ROOT/Packages/Sources"
[ -d "$SCAN" ] || SCAN="$ROOT"
violations=$(
find "$SCAN" -name '*.swift' -not -path '*/.build/*' -not -path '*/.git/*' -print | while IFS= read -r f; do
count=$(grep -cE '^(public |package |internal )?(actor|struct|enum|protocol|class|final class) [A-Z]' "$f" || true)
if [ "$count" -gt 1 ]; then
printf '%s %s\n' "$count" "$f"
fi
done
)
if [ -n "$violations" ]; then
echo "NAMESPACING FAIL (more than one non-private top-level type per file):" >&2
echo "$violations" >&2
echo "Fix: split the file, or mark helper types private/fileprivate so they drop out of the count." >&2
exit 1
fi
echo "namespacing clean ($(find "$SCAN" -name '*.swift' -not -path '*/.build/*' | wc -l | tr -d ' ') swift files)"