mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-10 20:27:11 +01:00
Replace this repo's stale file-length hook with the shared gate every other
repo will use. The old hook capped at 500 lines, called a repo-local
scripts/check_file_length.py, and filtered to types_or: [python, shell] --
so it never looked at the Flutter app in app/ or at any prose. Two caps that
disagree is worse than one, so the old one is deleted rather than kept.
The new hook checks only the files in the commit and exits 1; CI runs --all
as the backstop, since a fresh clone that never ran `pre-commit install` has
no hooks at all. The exemption list lives with the checker in
~/utils/file_length/config.py so the gate and the cross-repo survey cannot
disagree about what "too long" means.
Two things this repo has that ~/todo (the reference implementation) did not:
- A pre-commit CI job running --all-files, where $HOME/utils does not exist.
The shared gate is checked out to .utils and reached via UTILS_ROOT, or the
hook fails on a missing checker rather than on anything in this repo.
- Tests that isolate live user state with dotted-string patches
(`patch("diet_guard._state.FOOD_LOG_FILE", ...)`). unittest.mock.patch fails
OPEN: once a refactor moves a name, the old path still imports, the patch
redirects nothing, the test still passes -- and the suite writes to the real
~/.local/share/diet_guard, which diet-guard-sync.timer publishes within 15
minutes. check_patch_targets.py resolves all 30 patch targets statically so
that failure is loud instead of silent. It is landed before any split for
exactly that reason.
The gate is red at 52 files; the splits that follow drive it to zero.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK3HCZrM75sRHL1gL8usve
32 lines
1.1 KiB
Bash
Executable File
32 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ============================================================================
|
|
# Fail if any file in the commit exceeds the shared 250-line cap.
|
|
#
|
|
# Thin delegate to the shared gate in ~/utils, which owns the cap and the
|
|
# exemption list (generated / vendored / data files). Copying that logic here
|
|
# is what lets one repo's idea of "too long" drift from every other repo's --
|
|
# so this script only locates the shared checker and forwards its arguments.
|
|
#
|
|
# Usage:
|
|
# scripts/check_file_length.sh <file> [<file> ...] # pre-commit passes these
|
|
# scripts/check_file_length.sh --all # whole tree, from cwd
|
|
# ============================================================================
|
|
|
|
set -euo pipefail
|
|
|
|
readonly SHARED_GATE="${UTILS_ROOT:-$HOME/utils}/scripts/check_file_length.sh"
|
|
|
|
main() {
|
|
if [[ ! -x "$SHARED_GATE" ]]; then
|
|
echo "Error: shared file-length gate not found at $SHARED_GATE" >&2
|
|
echo " Clone github.com/kuhyx/utils to ~/utils, or set" >&2
|
|
echo " UTILS_ROOT to where it lives." >&2
|
|
exit 1
|
|
fi
|
|
|
|
exec bash "$SHARED_GATE" "$@"
|
|
}
|
|
|
|
main "$@"
|