Skip to content

Commit 961ea88

Browse files
committed
refactor(typos): settings.configuration as attrs
1 parent dcf5072 commit 961ea88

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

modules/hooks.nix

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ let
44
cfg = config;
55
inherit (lib) flatten mapAttrs mapAttrsToList mkDefault mkOption mkRemovedOptionModule mkRenamedOptionModule types;
66

7+
toml = pkgs.formats.toml { };
8+
79
cargoManifestPathArg =
810
lib.optionalString
911
(settings.rust.cargoManifestPath != null)
@@ -1797,19 +1799,14 @@ in
17971799
};
17981800
configuration =
17991801
mkOption {
1800-
type = types.str;
1801-
description = "Multiline-string configuration passed as config file. If set, config set in `typos.settings.configPath` gets ignored.";
1802-
default = "";
1803-
example = ''
1804-
[files]
1805-
ignore-dot = true
1806-
1807-
[default]
1808-
binary = false
1809-
1810-
[type.py]
1811-
extend-glob = []
1812-
'';
1802+
type = toml.type;
1803+
description = "Configuration passed as config file. If set, config set in `typos.settings.configPath` gets ignored.";
1804+
default = { };
1805+
example = {
1806+
files.ignore-dot = true;
1807+
default.binary = false;
1808+
type.py.extend-glob = [ ];
1809+
};
18131810
};
18141811

18151812
configPath =
@@ -3988,16 +3985,15 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
39883985
package = tools.typos;
39893986
entry =
39903987
let
3991-
# Concatenate config in config file with section for ignoring words generated from list of words to ignore
3992-
configuration = "${hooks.typos.settings.configuration}" + lib.strings.optionalString (hooks.typos.settings.ignored-words != [ ]) "\n\[default.extend-words\]" + lib.strings.concatMapStrings (x: "\n${x} = \"${x}\"") hooks.typos.settings.ignored-words;
3993-
configFile = builtins.toFile "typos-config.toml" configuration;
3988+
inherit (hooks.typos.settings) configuration;
3989+
configFile = toml.generate "typos-config.toml" configuration;
39943990
cmdArgs =
39953991
mkCmdArgs
39963992
(with hooks.typos.settings; [
39973993
[ binary "--binary" ]
39983994
[ (color != "auto") "--color ${color}" ]
3999-
[ (configuration != "") "--config ${configFile}" ]
4000-
[ (configPath != "" && configuration == "") "--config ${configPath}" ]
3995+
[ true "--config ${configFile}" ]
3996+
[ (configPath != "" && configuration == { }) "--config ${configPath}" ]
40013997
[ diff "--diff" ]
40023998
[ (exclude != "") "--exclude ${exclude} --force-exclude" ]
40033999
[ (format != "long") "--format ${format}" ]
@@ -4012,6 +4008,9 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
40124008
]);
40134009
in
40144010
"${hooks.typos.package}/bin/typos ${cmdArgs}";
4011+
settings.configuration = {
4012+
default.extend-words = lib.genAttrs hooks.typos.settings.ignored-words lib.id;
4013+
};
40154014
types = [ "text" ];
40164015
};
40174016
typstfmt = {

0 commit comments

Comments
 (0)