Skip to content

Commit 3e585d3

Browse files
authored
Merge pull request #552 from gigamonster256/fmt-json-autofix
pretty-format-json: expose tool options in settings
2 parents b9650f1 + 324069d commit 3e585d3

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 {
@@ -3281,14 +3320,6 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
32813320
"${binPath} analyse";
32823321
types = [ "php" ];
32833322
};
3284-
pretty-format-json =
3285-
{
3286-
name = "pretty-format-json";
3287-
description = "Formats JSON files.";
3288-
package = tools.pre-commit-hooks;
3289-
entry = "${hooks.pretty-format-json.package}/bin/pretty-format-json";
3290-
types = [ "json" ];
3291-
};
32923323
poetry-check = {
32933324
name = "poetry check";
32943325
description = "Check the Poetry config for errors";
@@ -3376,6 +3407,25 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol
33763407
in
33773408
"${binPath} ${cmdArgs}";
33783409
};
3410+
pretty-format-json =
3411+
{
3412+
name = "pretty-format-json";
3413+
description = "Formats JSON files.";
3414+
package = tools.pre-commit-hooks;
3415+
entry =
3416+
let
3417+
binPath = "${hooks.pretty-format-json.package}/bin/pretty-format-json";
3418+
cmdArgs = mkCmdArgs (with hooks.pretty-format-json.settings; [
3419+
[ autofix "--autofix" ]
3420+
[ (indent != null) "--indent ${toString indent}" ]
3421+
[ no-ensure-ascii "--no-ensure-ascii" ]
3422+
[ no-sort-keys "--no-sort-keys" ]
3423+
[ (top-keys != [ ]) "--top-keys ${lib.strings.concatStringsSep "," top-keys}" ]
3424+
]);
3425+
in
3426+
"${binPath} ${cmdArgs}";
3427+
types = [ "json" ];
3428+
};
33793429
psalm =
33803430
{
33813431
name = "psalm";

0 commit comments

Comments
 (0)