Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
translate ▾

Modern-Apps.git / scripts / lint_rust_length.sh

lint_rust_length.sh48 lines · 1.4 KiBRaw
1#!/usr/bin/env bash
2# Verification script: flag Rust files longer than 500 lines.
3# Mirrors lint-rules FileLengthDetector (350 ui / 800 elsewhere for Kotlin),
4# which cannot see Rust — this covers *.rs instead. Advisory, like the other
5# 6 non-fatal custom rules: exit 0 always unless --strict is passed.
6# Excludes: target/ build output, generated files, vendored third-party,
7# test fixtures (long by nature, same rationale as the Kotlin rule).
8
9set -euo pipefail
10
11REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
12cd "$REPO_ROOT"
13
14LIMIT=500
15STRICT=0
16if [[ "${1:-}" == "--strict" ]]; then
17 STRICT=1
18fi
19
20echo "=== Rust file length audit (limit $LIMIT lines) ==="
21
22HITS=$(find library maps scripts -name '*.rs' -not -path '*/target/*' -not -path '*/build/*' \
23 | while read -r f; do
24 # Skip generated + vendored + test fixtures.
25 case "$f" in
26 */generated/*|*/third_party/*|*/tests/*|*/test_fixtures/*|*/examples/*) continue;;
27 esac
28 n=$(wc -l < "$f")
29 if [[ "$n" -gt "$LIMIT" ]]; then
30 echo "$n $f"
31 fi
32 done | sort -rn || true)
33
34if [[ -n "$HITS" ]]; then
35 echo "$HITS"
36 COUNT=$(echo "$HITS" | wc -l)
37 echo "Found $COUNT file(s) over $LIMIT lines — split along module lines so each file stays reviewable."
38else
39 echo "No Rust files over $LIMIT lines"
40 COUNT=0
41fi
42
43if [[ "$STRICT" -eq 1 && "$COUNT" -gt 0 ]]; then
44 echo "FAIL: Rust files exceed the length limit"
45 exit 1
46fi
47echo "PASS (advisory)"
48exit 0