From bcdac0442fe258af7b739d2b1141b2e6f12b0c5b Mon Sep 17 00:00:00 2001 From: wi11-holdsworth <83637728+wi11-holdsworth@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:16:56 +1000 Subject: [PATCH] refactor: replace manual pre-commit with a declarative, installable pre-commit hook via pre-commit.com --- .pre-commit | 11 ----------- .pre-commit-config.yaml | 27 +++++++++++++++++++++++++++ README.md | 11 ----------- modules/nixos/default.nix | 1 + 4 files changed, 28 insertions(+), 22 deletions(-) delete mode 100644 .pre-commit create mode 100644 .pre-commit-config.yaml delete mode 100644 README.md diff --git a/.pre-commit b/.pre-commit deleted file mode 100644 index b5aef27..0000000 --- a/.pre-commit +++ /dev/null @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f306bef --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 +# +# 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 diff --git a/README.md b/README.md deleted file mode 100644 index fd970aa..0000000 --- a/README.md +++ /dev/null @@ -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 -``` diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index 2d826a8..66ce7fa 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -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