diff --git a/modules/hooks.nix b/modules/hooks.nix index 63bcc1cb..4d25ddb5 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -1306,6 +1306,45 @@ in }; }; }; + pretty-format-json = mkOption + { + description = "pretty-format-json hook"; + type = types.submodule { + imports = [ hookModule ]; + options.settings = { + autofix = + mkOption { + type = types.bool; + description = "Automatically format JSON files."; + default = false; + }; + indent = + mkOption { + type = types.nullOr (types.oneOf [ types.int types.str ]); + description = "Control the indentation (either a number for a number of spaces or a string of whitespace). Defaults to 2 spaces."; + default = null; + }; + no-ensure-ascii = + mkOption { + type = types.bool; + description = "Preserve unicode characters instead of converting to escape sequences."; + default = false; + }; + no-sort-keys = + mkOption { + type = types.bool; + description = "When autofixing, retain the original key ordering (instead of sorting the keys)."; + default = false; + }; + top-keys = + mkOption { + type = types.listOf types.str; + description = "Keys to keep at the top of mappings."; + default = [ ]; + }; + }; + }; + }; psalm = mkOption { description = "psalm hook"; type = types.submodule { @@ -3247,14 +3286,6 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol "${binPath} analyse"; types = [ "php" ]; }; - pretty-format-json = - { - name = "pretty-format-json"; - description = "Formats JSON files."; - package = tools.pre-commit-hooks; - entry = "${hooks.pretty-format-json.package}/bin/pretty-format-json"; - types = [ "json" ]; - }; poetry-check = { name = "poetry check"; description = "Check the Poetry config for errors"; @@ -3342,6 +3373,25 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol in "${binPath} ${cmdArgs}"; }; + pretty-format-json = + { + name = "pretty-format-json"; + description = "Formats JSON files."; + package = tools.pre-commit-hooks; + entry = + let + binPath = "${hooks.pretty-format-json.package}/bin/pretty-format-json"; + cmdArgs = mkCmdArgs (with hooks.pretty-format-json.settings; [ + [ autofix "--autofix" ] + [ (indent != null) "--indent ${toString indent}" ] + [ no-ensure-ascii "--no-ensure-ascii" ] + [ no-sort-keys "--no-sort-keys" ] + [ (top-keys != [ ]) "--top-keys ${lib.strings.concatStringsSep "," top-keys}" ] + ]); + in + "${binPath} ${cmdArgs}"; + types = [ "json" ]; + }; psalm = { name = "psalm";