Enforce Rust code health gate
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
ROOT_DIR="${CRANK_RUST_HEALTH_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
|
||||
|
||||
DEFAULT_MAX_LINES=1000
|
||||
DEFAULT_MAX_LINES="${CRANK_RUST_HEALTH_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.
|
||||
@@ -46,7 +46,8 @@ while IFS=: read -r file line _; do
|
||||
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
|
||||
echo "error: $rel contains inline tests and has $lines lines; move integration-style tests to tests/" >&2
|
||||
status=1
|
||||
fi
|
||||
done < <(
|
||||
grep -RIn --include='*.rs' '^[[:space:]]*mod tests[[:space:]]*{' \
|
||||
@@ -61,7 +62,8 @@ 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/.
|
||||
- large inline test modules are forbidden outside the legacy allowlist;
|
||||
- when touching a large file, extract modules or move integration-style tests to tests/.
|
||||
|
||||
EOF
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user