From 8a044142cbf86ffa6bd445db7d129f9ac051d608 Mon Sep 17 00:00:00 2001 From: Willem Jiang Date: Sun, 26 Apr 2026 09:40:17 +0800 Subject: [PATCH] feat(dev): add pre-commit hooks for ruff, eslint, and prettier (#2525) * feat(dev): add pre-commit hooks for ruff, eslint, and prettier * fix: use local uv-based ruff hooks and uv run for pre-commit install Agent-Logs-Url: https://github.com/bytedance/deer-flow/sessions/a1e34cc5-0d4b-4400-9e6a-e687d964ff1e Co-authored-by: WillemJiang <219644+WillemJiang@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- .pre-commit-config.yaml | 33 +++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 2 +- Makefile | 4 +++- README.md | 2 +- 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..c79d53b51 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +repos: + # Backend: ruff lint + format via uv (uses the same ruff version as backend deps) + - repo: local + hooks: + - id: ruff + name: ruff lint + entry: bash -c 'cd backend && uv run ruff check --fix "${@/#backend\//}"' -- + language: system + types_or: [python] + files: ^backend/ + - id: ruff-format + name: ruff format + entry: bash -c 'cd backend && uv run ruff format "${@/#backend\//}"' -- + language: system + types_or: [python] + files: ^backend/ + + # Frontend: eslint + prettier (must run from frontend/ for node_modules resolution) + - repo: local + hooks: + - id: frontend-eslint + name: eslint (frontend) + entry: bash -c 'cd frontend && npx eslint --fix "${@/#frontend\//}"' -- + language: system + types_or: [javascript, tsx, ts] + files: ^frontend/ + + - id: frontend-prettier + name: prettier (frontend) + entry: bash -c 'cd frontend && npx prettier --write "${@/#frontend\//}"' -- + language: system + files: ^frontend/ + types_or: [javascript, tsx, ts, json, css] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 241ca71af..b7cb2840b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -166,7 +166,7 @@ Required tools: 1. **Configure the application** (same as Docker setup above) -2. **Install dependencies**: +2. **Install dependencies** (this also sets up pre-commit hooks): ```bash make install ``` diff --git a/Makefile b/Makefile index b21d860ae..0d31b7c9f 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ help: @echo " make config - Generate local config files (aborts if config already exists)" @echo " make config-upgrade - Merge new fields from config.example.yaml into config.yaml" @echo " make check - Check if all required tools are installed" - @echo " make install - Install all dependencies (frontend + backend)" + @echo " make install - Install all dependencies (frontend + backend + pre-commit hooks)" @echo " make setup-sandbox - Pre-pull sandbox container image (recommended)" @echo " make dev - Start all services in development mode (with hot-reloading)" @echo " make dev-pro - Start in dev + Gateway mode (experimental, no LangGraph server)" @@ -73,6 +73,8 @@ install: @cd backend && uv sync @echo "Installing frontend dependencies..." @cd frontend && pnpm install + @echo "Installing pre-commit hooks..." + @$(BACKEND_UV_RUN) --with pre-commit pre-commit install @echo "✓ All dependencies installed" @echo "" @echo "==========================================" diff --git a/README.md b/README.md index e9ca2c174..59461ee99 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,7 @@ On Windows, run the local development flow from Git Bash. Native `cmd.exe` and P 2. **Install dependencies**: ```bash - make install # Install backend + frontend dependencies + make install # Install backend + frontend dependencies + pre-commit hooks ``` 3. **(Optional) Pre-pull sandbox image**: