refactor: replace manual pre-commit with a declarative, installable pre-commit hook via pre-commit.com

This commit is contained in:
wi11-holdsworth 2025-10-01 15:16:56 +10:00
parent 6daa32c222
commit bcdac0442f
4 changed files with 28 additions and 22 deletions

View file

@ -1,11 +0,0 @@
#!/bin/sh
FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0
# Prettify all selected files
echo "$FILES" | xargs keep-sorted
# Add back the modified files to staging
echo "$FILES" | xargs git add
exit 0

27
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,27 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
#
# Install pre-commit itself:
# $ pip install pre-commit
# OR
# $ brew install pre-commit
#
# Update all pre-commit hooks to latest version:
# $ pre-commit autoupdate
#
# Install all default pre-commit hooks locally:
# $ pre-commit install
#
# Apply a given pre-commit hook to all files:
# $ pre-commit run --all-files <id>
#
# Apply all pre-commit hooks to all files:
# $ pre-commit run --all-files
ci:
autoupdate_schedule: monthly
submodules: true
repos:
- repo: https://github.com/google/keep-sorted
rev: c71803fd297b5736f3bfab1cfd84424ca52e961a # frozen: v0.7.1
hooks:
- id: keep-sorted

View file

@ -1,11 +0,0 @@
# dots
## build
### `keep-sorted` pre-commit hook
copy the pre-commit hook to `.git/hooks`
```bash
cp .pre-commit .git/hooks/pre-commit
```
make it executable
```bash
chmod +x .git/hooks/pre-commit
```

View file

@ -57,6 +57,7 @@ in
pastel # colour generation
pdd # datetime calculations
pirate-get # torrenting
pre-commit # declarative pre-commit installer and runner
procs # ps
rates # currency conversion
ripgrep-all # grep