PureXML/third_party/rules-swift/.githooks/pre-commit
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

34 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# Pre-commit hook: leak gate on every commit, then format and lint staged Swift files.
# Install per clone (hooks are not cloned): git config core.hooksPath .githooks
# See formatting-and-linting.md. CI re-runs both over the whole tree as the hard gate.
set -e
# Public-safe leak gate runs on EVERY commit (this repo is mostly markdown, so it must
# not be gated behind staged Swift files). See scripts/leak-gate.sh.
sh "$(dirname "$0")/../scripts/leak-gate.sh"
# Namespacing gate (one non-private top-level type per file) runs whole-tree on every
# commit, matching code-style.md. Cheap, and vacuous in a repo with no Swift sources.
sh "$(dirname "$0")/../scripts/check-namespacing.sh"
# Lint only the Swift this commit touches. A commit with no Swift files (docs, config,
# this rules repo) has nothing to format or lint, so stop here.
swift_files=$(git diff --cached --name-only --diff-filter=ACM -- '*.swift')
if [ -z "$swift_files" ]; then
exit 0
fi
if command -v swiftformat >/dev/null 2>&1; then
printf '%s\n' "$swift_files" | xargs swiftformat --lint --config .swiftformat
else
echo "pre-commit: swiftformat not found; install it so formatting is enforced locally." >&2
fi
if command -v swiftlint >/dev/null 2>&1; then
printf '%s\n' "$swift_files" | xargs swiftlint lint --strict --config .swiftlint.yml
else
echo "pre-commit: swiftlint not found; install it so linting is enforced locally." >&2
fi