Skip to content

Commit

Permalink
Add more options to typos hook
Browse files Browse the repository at this point in the history
  • Loading branch information
totoroot committed Jan 15, 2024
1 parent ffa9a5b commit 7a06a89
Showing 1 changed file with 57 additions and 21 deletions.
78 changes: 57 additions & 21 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1087,17 +1087,22 @@ in
};
typos =
{
binary =
mkOption {
type = types.bool;
description = lib.mdDoc "Whether to search binary files.";
default = false;
};
color =
mkOption {
type = types.enum [ "auto" "always" "never" ];
description = lib.mdDoc "When to use generate output.";
default = "auto";
};

config =
mkOption {
type = types.str;
description = lib.mdDoc "Multiline-string configuration passed as config file.";
description = lib.mdDoc "Multiline-string configuration passed as config file. If set, config set in `typos.settings.configPath` gets ignored.";
default = "";
example = ''
[files]
Expand All @@ -1110,55 +1115,78 @@ in
extend-glob = []
'';
};

configPath =
mkOption {
type = types.str;
description = lib.mdDoc "Path to a custom config file.";
default = "";
example = ".typos.toml";
};

diff =
mkOption {
type = types.bool;
description = lib.mdDoc "Whether to print a diff of what would change.";
description = lib.mdDoc "Print a diff of what would change.";
default = false;
};

exclude =
mkOption {
type = types.str;
description = lib.mdDoc "Which files & directories to exclude matching the glob.";
description = lib.mdDoc "Ignore files and directories matching the glob.";
default = "";
example = "*.nix";
};

format =
mkOption {
type = types.enum [ "silent" "brief" "long" "json" ];
description = lib.mdDoc "Which output format to use.";
description = lib.mdDoc "Output format to use.";
default = "long";
};

hidden =
mkOption {
type = types.bool;
description = lib.mdDoc "Whether to search hidden files and directories.";
description = lib.mdDoc "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";
};

no-check-filenames =
mkOption {
type = types.bool;
description = lib.mdDoc "Skip verifying spelling in file names.";
default = false;
};
no-check-files =
mkOption {
type = types.bool;
description = lib.mdDoc "Skip verifying spelling in files.";
default = false;
};
no-unicode =
mkOption {
type = types.bool;
description = lib.mdDoc "Only allow ASCII characters in identifiers.";
default = false;
};
quiet =
mkOption {
type = types.bool;
description = lib.mdDoc "Less output per occurence.";
default = false;
};
verbose =
mkOption {
type = types.bool;
description = lib.mdDoc "More output per occurence.";
default = false;
};
write =
mkOption {
type = types.bool;
description = lib.mdDoc "Whether to fix spelling in files by writing them. Cannot be used with `typos.settings.diff`.";
description = lib.mdDoc "Fix spelling in files by writing them. Cannot be used with `typos.settings.diff`.";
default = false;
};
};
Expand Down Expand Up @@ -2423,20 +2451,28 @@ in
description = "Source code spell checker";
entry =
let
configFile = builtins.toFile "config.toml" "${settings.typos.config}";
configFile = builtins.toFile "typos-config.toml" "${settings.typos.config}";
cmdArgs =
mkCmdArgs
(with settings.typos; [
[ (color != "") "--color ${color}" ]
[ (configPath != "") "--config ${configPath}" ]
[ (config != "" && configPath == "") "--config ${configFile}" ]
[ binary "--binary" ]
[ (color != "auto") "--color ${color}" ]
[ (config != "") "--config ${configFile}" ]
[ (configPath != "" && config == "") "--config ${configPath}" ]
[ diff "--diff" ]
[ (exclude != "") "--exclude ${exclude} --force-exclude" ]
[ (format != "") "--format ${format}" ]
[ (locale != "") "--locale ${locale}" ]
[ (format != "long") "--format ${format}" ]
[ hidden "--hidden" ]
[ (locale != "en") "--locale ${locale}" ]
[ no-check-filenames "--no-check-filenames" ]
[ no-check-files "--no-check-files" ]
[ no-unicode "--no-unicode" ]
[ quiet "--quiet" ]
[ verbose "--verbose" ]
[ (write && !diff) "--write-changes" ]
]);
in
"${tools.typos}/bin/typos ${cmdArgs}${lib.optionalString settings.typos.diff " --diff"}${lib.optionalString settings.typos.hidden " --hidden"}";
"${tools.typos}/bin/typos ${cmdArgs}";
types = [ "text" ];
# Typos is supposed to run on the whole tree. If this is set to true,
# the system gets stuck for large projects due to very high memory
Expand Down

0 comments on commit 7a06a89

Please sign in to comment.