#!/usr/bin/env bash # Cross-cutting static scan for a full codebase review: things that can be counted without reading. # Usage: scan.sh [source-root] (default: src if it exists, else .) set -uo pipefail ROOT="${1:-}" if [ -z "$ROOT" ]; then if [ -d src ]; then ROOT=src; else ROOT=.; fi fi EXCLUDES=(--exclude-dir=node_modules --exclude-dir=dist --exclude-dir=build --exclude-dir=coverage) if [[ "$ROOT" =~ (^|/)(client|web|frontend)(/|$) ]]; then CLIENT_DIR="$ROOT" # scanning a folder inside the client (e.g. review --module) else CLIENT_DIR=$(find "$ROOT" -maxdepth 2 -type d \( -name client -o -name web -o -name frontend \) ! -path '*/node_modules/*' | head -1) fi section() { printf '\n== %s\n' "$1"; } code_grep() { grep -rnE "${EXCLUDES[@]}" --include='*.ts' --include='*.tsx' "$@"; } non_test() { grep -vE '\.test\.tsx?:'; } count() { wc -l | tr -d ' '; } section "folder structure (rule A0, mandatory: src/{shared, server/{modules//{domain, application/{usecases, dto}, infra/{db, drivers}}, kernel}, client} + drizzle/)" if [ -d src ] && [ "$ROOT" = src ]; then bash "$(dirname "$0")/structure.sh" | sed 's/^/ /' else echo " skipped: run from the repo root with src/ (scanning $ROOT)" fi section "files/folders not in kebab-case" find "$ROOT" ! -path '*/node_modules/*' ! -path '*/meta/*' ! -name '.DS_Store' -print | awk -F/ '{print $NF}' \ | grep -vE '^[a-z0-9]+(-[a-z0-9]+)*(\.[a-z0-9]+(-[a-z0-9]+)*)*$' | grep -vE '^[0-9]{4}_[a-z0-9_]+\.sql$' | grep -vE '^\.$' \ | sort | uniq -c | head -20 section "focused/skipped tests (.only/.skip/.todo)" code_grep '\b(it|describe|test)\.(only|skip|todo)\b' "$ROOT" | head -20 section "type escapes" echo "@ts-ignore/@ts-expect-error/@ts-nocheck: $(code_grep '@ts-(ignore|expect-error|nocheck)' "$ROOT" | count)" echo "explicit any (non-test): $(code_grep ':\s*any\b|as any\b|' "$ROOT" | non_test | count)" section "lint/format tooling" LINTER=$(ls -a 2>/dev/null | grep -iE '^(\.?eslint|eslint\.config|biome|\.?oxlint|\.?prettier)' | tr '\n' ' ') echo "config files: ${LINTER:-none}" echo "eslint-disable comments: $(code_grep 'eslint-disable' "$ROOT" | count)$([ -z "$LINTER" ] && echo ' (no linter configured: these rules are never checked)')" section "console.* outside the client and tests" if [ -n "$CLIENT_DIR" ]; then code_grep 'console\.(log|warn|error|info|debug)' "$ROOT" | non_test | grep -v "^$CLIENT_DIR/" | cut -d: -f1 | sort | uniq -c | sort -rn | head -15 else code_grep 'console\.(log|warn|error|info|debug)' "$ROOT" | non_test | cut -d: -f1 | sort | uniq -c | sort -rn | head -15 fi section "throw statements outside the client and tests (expected: 0, except the transport-edge helper)" if [ -n "$CLIENT_DIR" ]; then THROWS=$(code_grep '(^|[^A-Za-z_.])throw[[:space:]]' "$ROOT" | non_test | grep -v "^$CLIENT_DIR/") else THROWS=$(code_grep '(^|[^A-Za-z_.])throw[[:space:]]' "$ROOT" | non_test) fi echo "total: $(printf '%s' "$THROWS" | grep -c . || true)" printf '%s\n' "$THROWS" | cut -d: -f1 | grep . | sort | uniq -c | sort -rn | head -10 section "database and media storage (expected: external Postgres, S3/MinIO)" DEPS=$(node -e "const p=require('./package.json'); console.log(Object.keys({...p.dependencies,...p.devDependencies}).join(' '))" 2>/dev/null) echo "embedded/local database packages: $(printf '%s\n' $DEPS | grep -xE 'better-sqlite3|sqlite3|@electric-sql/pglite|pg-mem|lowdb|nedb' | tr '\n' ' ' || true)" echo "S3 client package: $(printf '%s\n' $DEPS | grep -xE '@aws-sdk/client-s3|minio' | tr '\n' ' ' || true)" echo ".env.example has DATABASE_URL: $(grep -q '^DATABASE_URL' .env.example 2>/dev/null && echo yes || echo no)" echo ".env.example has S3_* keys: $(grep -qE '^S3_' .env.example 2>/dev/null && echo yes || echo no)" if [ -n "$CLIENT_DIR" ]; then DISK=$(code_grep '(writeFile|createWriteStream|appendFile)\(' "$ROOT" | non_test | grep -v "^$CLIENT_DIR/") else DISK=$(code_grep '(writeFile|createWriteStream|appendFile)\(' "$ROOT" | non_test) fi echo "server writes to local disk: $(printf '%s' "$DISK" | grep -c . || true)" printf '%s\n' "$DISK" | cut -d: -f1 | grep . | sort -u | head -5 | sed 's/^/ /' section "TODO/FIXME/HACK" code_grep '\b(TODO|FIXME|HACK|XXX)\b' "$ROOT" | non_test | head -20 if [ -n "$CLIENT_DIR" ]; then section "client: raw HTML controls outside $CLIENT_DIR/components/ui (count / files)" for tag in '