Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-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 | |
| 9 | set -euo pipefail |
| 10 | |
| 11 | REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 12 | cd "$REPO_ROOT" |
| 13 | |
| 14 | LIMIT=500 |
| 15 | STRICT=0 |
| 16 | if [[ "${1:-}" == "--strict" ]]; then |
| 17 | STRICT=1 |
| 18 | fi |
| 19 | |
| 20 | echo "=== Rust file length audit (limit $LIMIT lines) ===" |
| 21 | |
| 22 | HITS=$(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 | |
| 34 | if [[ -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." |
| 38 | else |
| 39 | echo "No Rust files over $LIMIT lines" |
| 40 | COUNT=0 |
| 41 | fi |
| 42 | |
| 43 | if [[ "$STRICT" -eq 1 && "$COUNT" -gt 0 ]]; then |
| 44 | echo "FAIL: Rust files exceed the length limit" |
| 45 | exit 1 |
| 46 | fi |
| 47 | echo "PASS (advisory)" |
| 48 | exit 0 |