import os
import sys
MAX_LINES = 800
SENTINEL = "foldit:allow-long-file"
SENTINEL_HEAD_LINES = 10
SRC_DIRS = ["src"]
files = [
os.path.join(r, f)
for d in SRC_DIRS
for r, _, fs in os.walk(d)
for f in fs
if f.endswith(".rs") and "target" not in r
]
def over_limit(path):
with open(path, encoding="utf-8", errors="replace") as fh:
lines = fh.readlines()
if any(SENTINEL in ln for ln in lines[:SENTINEL_HEAD_LINES]):
return None
return len(lines) if len(lines) > MAX_LINES else None
bad = [(f, n) for f in files for n in [over_limit(f)] if n is not None]
for f, n in sorted(bad, key=lambda x: -x[1]):
print(f"ERROR: {f} has {n} lines (max {MAX_LINES})")
sys.exit(1 if bad else 0)