Skip to content
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
50 changes: 48 additions & 2 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1753,11 +1753,46 @@ in
type = types.submodule {
imports = [ hookModule ];
options.settings = {
language-dialect = mkOption {
type = types.enum [ "auto" "bash" "posix" "mksh" "bats" ];
description = lib.mdDoc "Shell language dialect.";
default = "auto";
};
simplify = mkOption {
type = types.bool;
description = "Simplify the code.";
default = true;
};
indent = mkOption {
type = types.nullOr (types.oneOf [ types.int types.str ]);
description = lib.mdDoc "0 for tabs, >0 for number of spaces.";
default = null;
};
binary-next-line = mkOption {
type = types.bool;
description = lib.mdDoc "Binary ops like && and | may start a line.";
default = false;
};
case-indent = mkOption {
type = types.bool;
description = lib.mdDoc "Switch cases will be indented.";
default = false;
};
space-redirects = mkOption {
type = types.bool;
description = lib.mdDoc "Redirect operators will be followed by a space.";
default = false;
};
keep-padding = mkOption {
type = types.bool;
description = lib.mdDoc "Keep column alignment paddings.";
default = false;
};
func-next-line = mkOption {
type = types.bool;
description = lib.mdDoc "Function opening braces are placed on a separate line.";
default = false;
};
};
};
};
Expand Down Expand Up @@ -3983,9 +4018,20 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
package = tools.shfmt;
entry =
let
simplify = if hooks.shfmt.settings.simplify then "-s" else "";
cmdArgs =
mkCmdArgs
(with hooks.shfmt.settings; [
[ true "-ln ${language-dialect}" ]
[ simplify "-s" ]
[ (indent != null) "-i ${builtins.toString indent}" ]
[ binary-next-line "-bn" ]
[ case-indent "-ci" ]
[ space-redirects "-sr" ]
[ keep-padding "-kp" ]
[ func-next-line "-fn" ]
]);
in
"${hooks.shfmt.package}/bin/shfmt -w -l ${simplify}";
"${hooks.shfmt.package}/bin/shfmt -w -l ${cmdArgs}";
};
single-quoted-strings =
{
Expand Down