diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 6b86cc7..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,37 +0,0 @@ -# Pre-commit hooks for this Java/Maven project (the Java-conventional -# equivalent of husky hooks in JS projects). -# -# All hooks are CHECK-ONLY (no auto-fix): -# - lint via `mvn checkstyle:check` -# - format via `mvn spotless:check` (use `mvn spotless:apply` manually to fix) -# - unit tests via `mvn test` (integration tests tagged `integration` are -# already excluded from the default build via surefire `excludedGroups` -# in pom.xml, so no live backend is needed) -# -# Install/activate (per clone): -# pip install pre-commit # or: brew install pre-commit -# pre-commit install -# -# Run manually: -# pre-commit run --all-files -repos: - - repo: local - hooks: - - id: checkstyle-check - name: "lint: mvn checkstyle:check" - entry: mvn -B checkstyle:check - language: system - pass_filenames: false - always_run: true - - id: spotless-check - name: "format: mvn spotless:check" - entry: mvn -B spotless:check - language: system - pass_filenames: false - always_run: true - - id: unit-tests - name: "test: mvn test (unit only, integration excluded)" - entry: mvn -B test - language: system - pass_filenames: false - always_run: true diff --git a/README.md b/README.md index af9c318..98b8dbb 100644 --- a/README.md +++ b/README.md @@ -60,11 +60,11 @@ MOCK_DATA=true mvn javafx:run .\setup.ps1 # macOS / Linux: -pip install pre-commit -pre-commit install +brew install lefthook +lefthook install ``` -Ручная проверка всего сразу: `pre-commit run --all-files`. +Ручная проверка всего сразу: `lefthook run pre-commit`. Если упал формат — поправить: `mvn spotless:apply`. ## RBAC diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 0000000..d9871e9 --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,24 @@ +# Lefthook config for this Java/Maven project (replaces pre-commit). +# +# All jobs are CHECK-ONLY (no auto-fix): +# - lint via `mvn checkstyle:check` +# - format via `mvn spotless:check` (use `mvn spotless:apply` manually to fix) +# - unit tests via `mvn test` (integration tests tagged `integration` are +# already excluded from the default build via surefire `excludedGroups` +# in pom.xml, so no live backend is needed) +# +# Install/activate (per clone): +# brew install lefthook # or: winget install evilmartians.lefthook / scoop install lefthook +# lefthook install +# +# Run manually: +# lefthook run pre-commit +pre-commit: + parallel: false + jobs: + - name: "lint: mvn checkstyle:check" + run: mvn -B checkstyle:check + - name: "format: mvn spotless:check" + run: mvn -B spotless:check + - name: "test: mvn test (unit only, integration excluded)" + run: mvn -B test diff --git a/setup.ps1 b/setup.ps1 index 1a11d1d..c973c05 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -1,9 +1,9 @@ <# .SYNOPSIS - Sets up git pre-commit hooks for this repo (pre-commit framework). + Sets up git hooks for this repo (lefthook). .DESCRIPTION - Installs the `pre-commit` package if missing and runs `pre-commit install` + Installs `lefthook` if missing and runs `lefthook install` so the lint/format/unit-test checks run automatically on every `git commit`. Works on Windows PowerShell 5.1 and PowerShell 7+. #> @@ -18,12 +18,6 @@ if (-not (Test-Command 'git')) { exit 1 } -$Python = if (Test-Command 'python') { 'python' } elseif (Test-Command 'python3') { 'python3' } else { $null } -if (-not $Python) { - Write-Error 'Python not found in PATH. Install Python 3 (python.org) with "Add to PATH" and retry.' - exit 1 -} - # Must run inside the repo so hooks land in .git/hooks. $null = git rev-parse --show-toplevel 2>$null if ($LASTEXITCODE -ne 0) { @@ -31,14 +25,20 @@ if ($LASTEXITCODE -ne 0) { exit 1 } -& $Python -m pre_commit --version > $null 2>&1 -if ($LASTEXITCODE -ne 0) { - Write-Host 'pre-commit not found, installing via pip...' - & $Python -m pip install --user pre-commit +if (-not (Test-Command 'lefthook')) { + if (Test-Command 'winget') { + Write-Host 'lefthook not found, installing via winget...' + winget install --exact --id evilmartians.lefthook + } elseif (Test-Command 'scoop') { + Write-Host 'lefthook not found, installing via scoop...' + scoop install lefthook + } else { + Write-Error 'lefthook not found in PATH. Install it (winget install evilmartians.lefthook, or scoop install lefthook) and retry.' + exit 1 + } } -# Use `python -m` so it works even if pip --user Scripts dir is not on PATH. -& $Python -m pre_commit install +lefthook install Write-Host '' Write-Host 'Done. Hooks will run on every commit.' -Write-Host 'To check everything right now: pre-commit run --all-files' +Write-Host 'To check everything right now: lefthook run pre-commit'