70 lines
1.9 KiB
Bash
Executable File
70 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
|
DEFAULT_MAX_LINES=1000
|
|
|
|
# Existing debt baseline. New files must stay under DEFAULT_MAX_LINES. These
|
|
# files are allowed to exist, but CI fails if they grow further.
|
|
declare -A FILE_LIMITS=(
|
|
["apps/admin-api/src/service.rs"]=4112
|
|
["apps/admin-api/src/app.rs"]=3823
|
|
["apps/mcp-server/src/main.rs"]=3505
|
|
["crates/crank-runtime/src/executor.rs"]=2829
|
|
["crates/crank-registry/src/postgres/mod.rs"]=2154
|
|
["crates/crank-community-mcp/src/app.rs"]=1647
|
|
["crates/crank-registry/src/postgres/operation.rs"]=1022
|
|
)
|
|
|
|
status=0
|
|
|
|
echo "Rust code health: checking file size limits"
|
|
|
|
while IFS= read -r file; do
|
|
rel="${file#"$ROOT_DIR"/}"
|
|
lines="$(wc -l < "$file" | tr -d ' ')"
|
|
limit="${FILE_LIMITS[$rel]:-$DEFAULT_MAX_LINES}"
|
|
|
|
if (( lines > limit )); then
|
|
echo "error: $rel has $lines lines; limit is $limit" >&2
|
|
status=1
|
|
fi
|
|
done < <(
|
|
find "$ROOT_DIR" \
|
|
-path "$ROOT_DIR/target" -prune -o \
|
|
-path "$ROOT_DIR/apps/ui/node_modules" -prune -o \
|
|
-name '*.rs' -print | sort
|
|
)
|
|
|
|
echo "Rust code health: checking new large inline test modules"
|
|
|
|
while IFS=: read -r file line _; do
|
|
rel="${file#"$ROOT_DIR"/}"
|
|
if [[ -n "${FILE_LIMITS[$rel]:-}" ]]; then
|
|
continue
|
|
fi
|
|
lines="$(wc -l < "$file" | tr -d ' ')"
|
|
if (( lines > DEFAULT_MAX_LINES / 2 )); then
|
|
echo "warning: $rel contains inline tests and has $lines lines; prefer tests/ for integration-style tests" >&2
|
|
fi
|
|
done < <(
|
|
grep -RIn --include='*.rs' '^[[:space:]]*mod tests[[:space:]]*{' \
|
|
"$ROOT_DIR/apps" "$ROOT_DIR/crates" || true
|
|
)
|
|
|
|
if (( status != 0 )); then
|
|
cat >&2 <<'EOF'
|
|
|
|
Rust code health failed.
|
|
|
|
Rules:
|
|
- new Rust files must stay at or below 1000 lines;
|
|
- existing large files are pinned to the current baseline and must not grow;
|
|
- when touching a large file, prefer extracting modules or moving integration-style tests to tests/.
|
|
|
|
EOF
|
|
fi
|
|
|
|
exit "$status"
|