Skip to content

Commit d3de8f6

Browse files
authored
Merge pull request #276 from Niols/cleaner-errors-topiary-absent
Cleaner errors when Topiary is absent
2 parents e1e6c9a + ea689b2 commit d3de8f6

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

modules/hooks.nix

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -861,24 +861,34 @@ in
861861
entry = "${tools.hunspell}/bin/hunspell -l";
862862
files = "\\.((txt)|(html)|(xml)|(md)|(rst)|(tex)|(odf)|\\d)$";
863863
};
864+
864865
topiary =
865866
{
866867
name = "topiary";
867868
description = "A universal formatter engine within the Tree-sitter ecosystem, with support for many languages.";
868869
entry =
869-
let
870-
topiary-inplace = pkgs.writeShellApplication {
871-
name = "topiary-inplace";
872-
text = ''
873-
for file; do
874-
${tools.topiary}/bin/topiary --in-place --input-file "$file"
875-
done
876-
'';
877-
};
878-
in
879-
"${topiary-inplace}/bin/topiary-inplace";
870+
## NOTE: Topiary landed in nixpkgs on 2 Dec 2022. Once it reaches a
871+
## release of NixOS, the `throwIf` piece of code below will become
872+
## useless.
873+
lib.throwIf
874+
(tools.topiary == null)
875+
"The version of nixpkgs used by pre-commit-hooks.nix does not have the `topiary` package. Please use a more recent version of nixpkgs."
876+
(
877+
let
878+
topiary-inplace = pkgs.writeShellApplication {
879+
name = "topiary-inplace";
880+
text = ''
881+
for file; do
882+
${tools.topiary}/bin/topiary --in-place --input-file "$file"
883+
done
884+
'';
885+
};
886+
in
887+
"${topiary-inplace}/bin/topiary-inplace"
888+
);
880889
files = "(\\.json$)|(\\.toml$)|(\\.mli?$)";
881890
};
891+
882892
typos =
883893
{
884894
name = "typos";

0 commit comments

Comments
 (0)