From 29732f19a2a9e0d9e7a5bad953c4fad6f719c50e Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Sat, 15 Mar 2025 18:01:55 -0700 Subject: [PATCH] pre-commit: add `keep-sorted` hook This sorts lines alphabetically between `keep-sorted start` and `keep-sorted end` markers. See: https://github.com/google/keep-sorted Closes #730 Change-Id: Ib36f3da81fcf5e2f588ffb998860456405607eea --- lix/nix/main.cc | 18 +++++++++++------- misc/pre-commit.nix | 5 +++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lix/nix/main.cc b/lix/nix/main.cc index 6c7e48bad..fa1735906 100644 --- a/lix/nix/main.cc +++ b/lix/nix/main.cc @@ -59,12 +59,14 @@ void registerLegacyCommands() static bool haveProxyEnvironmentVariables() { static const std::vector proxyVariables = { - "http_proxy", - "https_proxy", - "ftp_proxy", - "HTTP_PROXY", + // keep-sorted start + "FTP_PROXY", "HTTPS_PROXY", - "FTP_PROXY" + "HTTP_PROXY", + "ftp_proxy", + "http_proxy", + "https_proxy" + // keep-sorted end }; for (auto & proxyVariable: proxyVariables) { if (getEnv(proxyVariable).has_value()) { @@ -168,6 +170,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs } std::map> aliases = { + // keep-sorted start {"add-to-store", {"store", "add-path"}}, {"cat-nar", {"nar", "cat"}}, {"cat-store", {"store", "cat"}}, @@ -182,13 +185,14 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs {"make-content-addressable", {"store", "make-content-addressed"}}, {"optimise-store", {"store", "optimise"}}, {"ping-store", {"store", "ping"}}, - {"sign-paths", {"store", "sign"}}, - {"show-derivation", {"derivation", "show"}}, {"show-config", {"config", "show"}}, + {"show-derivation", {"derivation", "show"}}, + {"sign-paths", {"store", "sign"}}, {"to-base16", {"hash", "to-base16"}}, {"to-base32", {"hash", "to-base32"}}, {"to-base64", {"hash", "to-base64"}}, {"verify", {"store", "verify"}}, + // keep-sorted end }; bool aliasUsed = false; diff --git a/misc/pre-commit.nix b/misc/pre-commit.nix index de44bf9e1..ade677152 100644 --- a/misc/pre-commit.nix +++ b/misc/pre-commit.nix @@ -96,6 +96,11 @@ pre-commit-run { ]; entry = lib.getExe pkgs.check-headers; }; + keep-sorted = { + enable = true; + package = pkgs.keep-sorted; + entry = lib.getExe pkgs.keep-sorted; + }; # TODO: Once the test suite is nicer, clean up and start # enforcing trailing whitespace on tests that don't explicitly # check for it.