PureXML/scripts/check-namespacing.sh
Mihaela Mihaljevic 708390242c chore: scaffold PureXML pure-Swift XML package
Root Swift package mirroring PureYAML's structure, rules, and verification
gates. Includes the XML node model (Node, Element, Attribute, QualifiedName),
a working emitter (Serializer) with escaping and pretty/compact options, and
structural validation. The parser surface is stable; parse() raises
notImplemented until the scanner lands, pinned by a test.

- dependency-free, namespaced under PureXML
- portability and style gates carried over (style, namespacing, forbidden
  patterns, swiftformat, swiftlint, linux, wasm, windows CI)
- 11 tests passing
2026-06-07 23:20:20 +02:00

41 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Namespacing gate (docs/rules/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: docs/rules/code-style.md" >&2
fi
exit "$FAIL"