Skip to content

Commit 115e9c9

Browse files
committed
chore(hooks): миграция с pre-commit на lefthook
1 parent 9c5a988 commit 115e9c9

4 files changed

Lines changed: 42 additions & 55 deletions

File tree

‎.pre-commit-config.yaml‎

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ MOCK_DATA=true mvn javafx:run
6060
.\setup.ps1
6161
6262
# macOS / Linux:
63-
pip install pre-commit
64-
pre-commit install
63+
brew install lefthook
64+
lefthook install
6565
```
6666

67-
Ручная проверка всего сразу: `pre-commit run --all-files`.
67+
Ручная проверка всего сразу: `lefthook run pre-commit`.
6868
Если упал формат — поправить: `mvn spotless:apply`.
6969

7070
## RBAC

‎lefthook.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Lefthook config for this Java/Maven project (replaces pre-commit).
2+
#
3+
# All jobs are CHECK-ONLY (no auto-fix):
4+
# - lint via `mvn checkstyle:check`
5+
# - format via `mvn spotless:check` (use `mvn spotless:apply` manually to fix)
6+
# - unit tests via `mvn test` (integration tests tagged `integration` are
7+
# already excluded from the default build via surefire `excludedGroups`
8+
# in pom.xml, so no live backend is needed)
9+
#
10+
# Install/activate (per clone):
11+
# brew install lefthook # or: winget install evilmartians.lefthook / scoop install lefthook
12+
# lefthook install
13+
#
14+
# Run manually:
15+
# lefthook run pre-commit
16+
pre-commit:
17+
parallel: false
18+
jobs:
19+
- name: "lint: mvn checkstyle:check"
20+
run: mvn -B checkstyle:check
21+
- name: "format: mvn spotless:check"
22+
run: mvn -B spotless:check
23+
- name: "test: mvn test (unit only, integration excluded)"
24+
run: mvn -B test

‎setup.ps1‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<#
22
.SYNOPSIS
3-
Sets up git pre-commit hooks for this repo (pre-commit framework).
3+
Sets up git hooks for this repo (lefthook).
44
55
.DESCRIPTION
6-
Installs the `pre-commit` package if missing and runs `pre-commit install`
6+
Installs `lefthook` if missing and runs `lefthook install`
77
so the lint/format/unit-test checks run automatically on every `git commit`.
88
Works on Windows PowerShell 5.1 and PowerShell 7+.
99
#>
@@ -18,27 +18,27 @@ if (-not (Test-Command 'git')) {
1818
exit 1
1919
}
2020

21-
$Python = if (Test-Command 'python') { 'python' } elseif (Test-Command 'python3') { 'python3' } else { $null }
22-
if (-not $Python) {
23-
Write-Error 'Python not found in PATH. Install Python 3 (python.org) with "Add to PATH" and retry.'
24-
exit 1
25-
}
26-
2721
# Must run inside the repo so hooks land in .git/hooks.
2822
$null = git rev-parse --show-toplevel 2>$null
2923
if ($LASTEXITCODE -ne 0) {
3024
Write-Error 'Not inside a git repository. Run this script from the repo root.'
3125
exit 1
3226
}
3327

34-
& $Python -m pre_commit --version > $null 2>&1
35-
if ($LASTEXITCODE -ne 0) {
36-
Write-Host 'pre-commit not found, installing via pip...'
37-
& $Python -m pip install --user pre-commit
28+
if (-not (Test-Command 'lefthook')) {
29+
if (Test-Command 'winget') {
30+
Write-Host 'lefthook not found, installing via winget...'
31+
winget install --exact --id evilmartians.lefthook
32+
} elseif (Test-Command 'scoop') {
33+
Write-Host 'lefthook not found, installing via scoop...'
34+
scoop install lefthook
35+
} else {
36+
Write-Error 'lefthook not found in PATH. Install it (winget install evilmartians.lefthook, or scoop install lefthook) and retry.'
37+
exit 1
38+
}
3839
}
3940

40-
# Use `python -m` so it works even if pip --user Scripts dir is not on PATH.
41-
& $Python -m pre_commit install
41+
lefthook install
4242
Write-Host ''
4343
Write-Host 'Done. Hooks will run on every commit.'
44-
Write-Host 'To check everything right now: pre-commit run --all-files'
44+
Write-Host 'To check everything right now: lefthook run pre-commit'

0 commit comments

Comments
 (0)