feat: add unified linting scripts and git hooks for code quality enforcement

- Introduced `lint` and `lint-fix` applications in `flake.nix` for unified linting of backend (Python) and frontend (TypeScript/Svelte) code.
- Added `scripts/lint.sh` for manual linting execution.
- Created `scripts/install-hooks.sh` to set up git hooks for automatic linting before commits and optional tests before pushes.
- Updated `README.md` with instructions for using the new linting features and git hooks.
This commit is contained in:
Danilo Reyes
2025-11-02 00:08:37 -06:00
parent 4c94793aba
commit b55ac51fe2
32 changed files with 470 additions and 171 deletions

131
scripts/lint.sh Executable file
View File

@@ -0,0 +1,131 @@
#!/usr/bin/env bash
# Unified linting script for all project code
# Can be run manually or via git hooks
set -e
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
FAILED=0
# Detect if we're in nix shell
if ! command -v ruff &> /dev/null && command -v nix &> /dev/null; then
echo "🔄 Entering nix development environment..."
exec nix develop -c bash "$0" "$@"
fi
echo "========================================="
echo "🔍 Reference Board Viewer - Code Linting"
echo "========================================="
echo ""
# Backend Python linting
echo -e "${BLUE}📦 Backend (Python)${NC}"
echo "-----------------------------------"
if [ -d "backend" ]; then
cd backend
# Ruff check
echo -n " Ruff check... "
if ruff check app/ 2>&1 | grep -q "All checks passed!"; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
echo ""
ruff check app/
FAILED=1
fi
# Ruff format check
echo -n " Ruff format... "
if ruff format --check app/ > /dev/null 2>&1; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
echo ""
echo "Run: cd backend && ruff format app/"
FAILED=1
fi
cd ..
else
echo -e "${YELLOW} ⚠ Backend directory not found, skipping${NC}"
fi
echo ""
# Frontend linting
echo -e "${BLUE}🎨 Frontend (TypeScript/Svelte)${NC}"
echo "-----------------------------------"
if [ -d "frontend" ] && [ -f "frontend/package.json" ]; then
cd frontend
# Check if node_modules exists
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW} ⚠ node_modules not found, run 'npm install' first${NC}"
cd ..
else
# ESLint
echo -n " ESLint... "
if npm run lint > /dev/null 2>&1; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
echo ""
npm run lint
FAILED=1
fi
# Prettier check
if [ -f ".prettierrc" ]; then
echo -n " Prettier... "
if npx prettier --check src/ > /dev/null 2>&1; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
echo ""
echo "Run: cd frontend && npx prettier --write src/"
FAILED=1
fi
fi
# TypeScript check
echo -n " TypeScript... "
if npm run check > /dev/null 2>&1; then
echo -e "${GREEN}${NC}"
else
echo -e "${RED}${NC}"
echo ""
npm run check
FAILED=1
fi
cd ..
fi
else
echo -e "${YELLOW} ⚠ Frontend directory not found, skipping${NC}"
fi
echo ""
echo "========================================="
if [ $FAILED -eq 0 ]; then
echo -e "${GREEN}✅ All linting checks passed!${NC}"
echo "========================================="
exit 0
else
echo -e "${RED}❌ Some linting checks failed${NC}"
echo "========================================="
echo ""
echo "To auto-fix issues:"
echo " Backend: cd backend && ruff check --fix app/ && ruff format app/"
echo " Frontend: cd frontend && npx prettier --write src/"
exit 1
fi