Skip to content

Commit 324069d

Browse files
pretty-format-json: expose tool options in settings
1 parent 9364dc0 commit 324069d

File tree

1 file changed

+58
-8
lines changed

1 file changed

+58
-8
lines changed

modules/hooks.nix

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,45 @@ in
13061306
};
13071307
};
13081308
};
1309+
pretty-format-json = mkOption
1310+
{
1311+
description = "pretty-format-json hook";
1312+
type = types.submodule {
1313+
imports = [ hookModule ];
1314+
options.settings = {
1315+
autofix =
1316+
mkOption {
1317+
type = types.bool;
1318+
description = "Automatically format JSON files.";
1319+
default = false;
1320+
};
1321+
indent =
1322+
mkOption {
1323+
type = types.nullOr (types.oneOf [ types.int types.str ]);
1324+
description = "Control the indentation (either a number for a number of spaces or a string of whitespace). Defaults to 2 spaces.";
1325+
default = null;
1326+
};
1327+
no-ensure-ascii =
1328+
mkOption {
1329+
type = types.bool;
1330+
description = "Preserve unicode characters instead of converting to escape sequences.";
1331+
default = false;
1332+
};
1333+
no-sort-keys =
1334+
mkOption {
1335+
type = types.bool;
1336+
description = "When autofixing, retain the original key ordering (instead of sorting the keys).";
1337+
default = false;
1338+
};
1339+
top-keys =
1340+
mkOption {
1341+
type = types.listOf types.str;
1342+
description = "Keys to keep at the top of mappings.";
1343+
default = [ ];
1344+
};
1345+
};
1346+
};
1347+
};
13091348
psalm = mkOption {
13101349
description = "psalm hook";
13111350
type = types.submodule {
@@ -3247,14 +3286,6 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
32473286
"${binPath} analyse";
32483287
types = [ "php" ];
32493288
};
3250-
pretty-format-json =
3251-
{
3252-
name = "pretty-format-json";
3253-
description = "Formats JSON files.";
3254-
package = tools.pre-commit-hooks;
3255-
entry = "${hooks.pretty-format-json.package}/bin/pretty-format-json";
3256-
types = [ "json" ];
3257-
};
32583289
poetry-check = {
32593290
name = "poetry check";
32603291
description = "Check the Poetry config for errors";
@@ -3342,6 +3373,25 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
33423373
in
33433374
"${binPath} ${cmdArgs}";
33443375
};
3376+
pretty-format-json =
3377+
{
3378+
name = "pretty-format-json";
3379+
description = "Formats JSON files.";
3380+
package = tools.pre-commit-hooks;
3381+
entry =
3382+
let
3383+
binPath = "${hooks.pretty-format-json.package}/bin/pretty-format-json";
3384+
cmdArgs = mkCmdArgs (with hooks.pretty-format-json.settings; [
3385+
[ autofix "--autofix" ]
3386+
[ (indent != null) "--indent ${toString indent}" ]
3387+
[ no-ensure-ascii "--no-ensure-ascii" ]
3388+
[ no-sort-keys "--no-sort-keys" ]
3389+
[ (top-keys != [ ]) "--top-keys ${lib.strings.concatStringsSep "," top-keys}" ]
3390+
]);
3391+
in
3392+
"${binPath} ${cmdArgs}";
3393+
types = [ "json" ];
3394+
};
33453395
psalm =
33463396
{
33473397
name = "psalm";

0 commit comments

Comments
 (0)