From b9ce83aa6b383407f9cb58f6eb5d1854f8ef4cd9 Mon Sep 17 00:00:00 2001 From: Matthias Thym Date: Thu, 3 Aug 2023 16:16:00 +0200 Subject: [PATCH] Add options to 'typos' hook Also sort options alphabetically --- modules/hooks.nix | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/modules/hooks.nix b/modules/hooks.nix index a9948692..dee7bdf5 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -286,11 +286,11 @@ in }; typos = { - write = + color = mkOption { - type = types.bool; - description = lib.mdDoc "Whether to write fixes out."; - default = false; + type = types.enum [ "auto" "always" "never" ]; + description = lib.mdDoc "When to use generate output."; + default = "auto"; }; diff = @@ -300,12 +300,41 @@ in default = false; }; + exclude = + mkOption { + type = types.str; + description = lib.mdDoc "Which files & directories to exclude matching the glob."; + default = ""; + example = "*.nix"; + }; + format = mkOption { type = types.enum [ "silent" "brief" "long" "json" ]; - description = lib.mdDoc "Output format."; + description = lib.mdDoc "Which output format to use."; default = "long"; }; + + hidden = + mkOption { + type = types.bool; + description = lib.mdDoc "Whether to search hidden files and directories."; + default = false; + }; + + locale = + mkOption { + type = types.enum [ "en" "en-us" "en-gb" "en-ca" "en-au" ]; + description = lib.mdDoc "Which language to use for spell checking."; + default = "en"; + }; + + write = + mkOption { + type = types.bool; + description = lib.mdDoc "Whether to write fixes out."; + default = false; + }; }; revive = @@ -1195,7 +1224,7 @@ in name = "typos"; description = "Source code spell checker"; entry = with settings.typos; - "${tools.typos}/bin/typos --format ${format} ${lib.optionalString write "-w"} ${lib.optionalString diff "--diff"}"; + "${tools.typos}/bin/typos --color ${color} ${lib.optionalString diff "--diff"} --exclude ${exclude} --format ${format} {lib.optionalString hidden " - -hidden "} --locale ${locale} ${lib.optionalString write "-write-changes"}"; types = [ "text" ]; };