Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pretty-format-json: expose tool options in settings #552

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 58 additions & 8 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down