From 8346dc308cf7192e1c1b645f1aac39ea69cba43e Mon Sep 17 00:00:00 2001 From: Matthias Thym Date: Thu, 3 Aug 2023 18:52:09 +0200 Subject: [PATCH 1/2] Fix wording of options and use `lib.mdDoc` --- modules/hooks.nix | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/hooks.nix b/modules/hooks.nix index 5b7fc8ae..4e5a012b 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -25,14 +25,14 @@ in { configPath = mkOption { type = types.str; - description = "path to the configuration YAML file"; + description = lib.mdDoc "Path to the YAML configuration file."; # an empty string translates to use default configuration of the # underlying ansible-lint binary default = ""; }; subdir = mkOption { type = types.str; - description = "path to Ansible subdir"; + description = lib.mdDoc "Path to the Ansible subdirectory."; default = ""; }; }; @@ -278,12 +278,13 @@ in configPath = mkOption { type = types.str; - description = "path to the configuration JSON file"; + description = lib.mdDoc "Path to the configuration JSON file"; # an empty string translates to use default configuration of the # underlying rome binary (i.e rome.json if exists) default = ""; }; }; + typos = { color = @@ -495,13 +496,13 @@ in { relaxed = mkOption { type = types.bool; - description = lib.mdDoc "Use the relaxed configuration"; + description = lib.mdDoc "Whether to use the relaxed configuration."; default = false; }; configPath = mkOption { type = types.str; - description = "path to the configuration YAML file"; + description = lib.mdDoc "Path to the YAML configuration file."; # an empty string translates to use default configuration of the # underlying yamllint binary default = ""; From 046d10f9d395cd8ee81e20b55e764b7a63bed500 Mon Sep 17 00:00:00 2001 From: Matthias Thym Date: Thu, 3 Aug 2023 18:52:34 +0200 Subject: [PATCH 2/2] Fix settings for typos and add some additional options --- modules/hooks.nix | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/modules/hooks.nix b/modules/hooks.nix index 4e5a012b..35004e08 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -294,6 +294,30 @@ in default = "auto"; }; + config = + mkOption { + type = types.str; + description = lib.mdDoc "Multiline-string configuration passed as config file."; + default = ""; + example = '' + [files] + ignore-dot = true + + [default] + binary = false + + [type.py] + extend-glob = [] + ''; + }; + + configPath = + mkOption { + type = types.str; + description = lib.mdDoc "Path to a custom config file."; + default = ""; + }; + diff = mkOption { type = types.bool; @@ -333,7 +357,7 @@ in write = mkOption { type = types.bool; - description = lib.mdDoc "Whether to write fixes out."; + description = lib.mdDoc "Whether to fix spelling in files by writing them. Cannot be used with `typos.settings.diff`."; default = false; }; }; @@ -1224,8 +1248,22 @@ in { name = "typos"; description = "Source code spell checker"; - entry = with settings.typos; - "${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"}"; + entry = + let + configFile = builtins.toFile "config.toml" "${settings.typos.config}"; + cmdArgs = + mkCmdArgs + (with settings.typos; [ + [ (color != "") "--color ${color}" ] + [ (configPath != "") "--config ${configPath}" ] + [ (config != "" && configPath == "") "--config ${configFile}" ] + [ (exclude != "") "--exclude ${exclude}" ] + [ (format != "") "--format ${format}" ] + [ (locale != "") "--locale ${locale}" ] + [ (write && !diff) "--write-changes" ] + ]); + in + "${tools.typos}/bin/typos ${cmdArgs}${lib.optionalString settings.typos.diff " --diff"}${lib.optionalString settings.typos.hidden " --hidden"}"; types = [ "text" ]; };