From d55382d16f66ff43c7019d73df158dbb68813d9a Mon Sep 17 00:00:00 2001 From: counterweight Date: Sun, 21 Dec 2025 22:01:38 +0100 Subject: [PATCH] Add pre-commit framework - Install pre-commit - Configure .pre-commit-config.yaml with: - ruff (lint + format) for Python - bandit for Python security - eslint for TypeScript - prettier for TypeScript - shared constants validation - Add Makefile targets: pre-commit, lint --- .pre-commit-config.yaml | 41 +++++++++++++++++++++++++++++++++++++++++ Makefile | 8 +++++++- backend/pyproject.toml | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..325d2ab --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,41 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.14.0 + hooks: + - id: ruff + args: [--fix] + files: ^backend/ + - id: ruff-format + files: ^backend/ + + - repo: https://github.com/PyCQA/bandit + rev: 1.8.0 + hooks: + - id: bandit + args: [-c, backend/pyproject.toml, -r] + files: ^backend/ + exclude: ^backend/(tests|\.venv)/ + + - repo: local + hooks: + - id: eslint + name: ESLint + entry: npm run lint --prefix frontend + language: system + files: ^frontend/.*\.(ts|tsx)$ + pass_filenames: false + + - id: prettier + name: Prettier + entry: npm run format:check --prefix frontend + language: system + files: ^frontend/ + pass_filenames: false + + - id: check-constants + name: Check shared constants + entry: bash -c 'cd backend && uv run python validate_constants.py' + language: system + files: shared/constants\.json$ + pass_filenames: false + diff --git a/Makefile b/Makefile index 952131c..eef0e3c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: install-backend install-frontend install setup-hooks backend frontend db db-stop db-ready db-seed dev test test-backend test-frontend test-e2e typecheck generate-types generate-types-standalone check-types-fresh check-constants lint-backend format-backend fix-backend security-backend lint-frontend fix-frontend format-frontend +.PHONY: install-backend install-frontend install setup-hooks backend frontend db db-stop db-ready db-seed dev test test-backend test-frontend test-e2e typecheck generate-types generate-types-standalone check-types-fresh check-constants lint-backend format-backend fix-backend security-backend lint-frontend fix-frontend format-frontend pre-commit lint -include .env export @@ -114,3 +114,9 @@ fix-frontend: format-frontend: cd frontend && npm run format + +pre-commit: + cd backend && uv run pre-commit run --all-files + +lint: lint-backend lint-frontend security-backend + @echo "All linting passed!" diff --git a/backend/pyproject.toml b/backend/pyproject.toml index c449ea3..af0c848 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -23,6 +23,7 @@ dev = [ "ruff>=0.14.10", "pytest-cov>=7.0.0", "bandit>=1.9.2", + "pre-commit>=4.5.1", ] [tool.mypy]