PureXML/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

41 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Namespacing gate (third_party/rules-swift/code-style.md): one non-private top-level type per
# file. A file with more than one file-scope type declaration is a violation:
# split it, or mark helper types private/fileprivate.
#
# Inert until Sources exists. Portable: bash 3.2 and 4+.
set -u
SRC="Sources"
if [ ! -d "$SRC" ]; then
echo "namespacing: no $SRC yet, skipping."
exit 0
fi
FAIL=0
while IFS= read -r f; do
count=$(grep -cE "^(public |package |internal )?(actor|struct|enum|protocol|class|final class) [A-Z]" "$f")
if [ "$count" -gt 1 ]; then
echo "namespacing: $count file-scope types in $f (one per file)" >&2
FAIL=1
fi
public_types=$(grep -nE "^public (actor|struct|enum|protocol|class|final class) [A-Z]" "$f" || true)
if [ -n "$public_types" ]; then
if [ "$f" = "Sources/PureXML.swift" ] &&
[ "$public_types" = "2:public enum PureXML {" ]; then
:
else
echo "namespacing: public file-scope type in $f (wrap it under PureXML)" >&2
printf '%s\n' "$public_types" | sed 's/^/ /' >&2
FAIL=1
fi
fi
done < <(find "$SRC" -name "*.swift")
if [ "$FAIL" -ne 0 ]; then
echo "namespacing: gate failed. Rule: third_party/rules-swift/code-style.md" >&2
fi
exit "$FAIL"