Skip to content

Commit 85eaf0e

Browse files
authored
Merge pull request #583 from bmrips/typos-improvements
typos improvements
2 parents 95d5446 + 6007ee9 commit 85eaf0e

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

modules/hooks.nix

Lines changed: 40 additions & 25 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)
@@ -33,6 +35,9 @@ in
3335
(mkRemovedOptionModule [ "settings" "yamllint" "relaxed" ] ''
3436
This option has been removed. Use `hooks.yamllint.settings.preset = "relaxed"`.
3537
'')
38+
(mkRemovedOptionModule [ "typos" "settings" "configuration" ] ''
39+
This option has been removed. Use `hooks.typos.settings.config`, which is a structured attrs, instead.
40+
'')
3641
]
3742
# Manually rename options that had a package or a config option
3843
++ flatten (mapAttrsToList (name: map (o: mkRenamedOptionModule [ "settings" name o ] [ "hooks" name "settings" o ])) {
@@ -1803,33 +1808,30 @@ in
18031808
description = "Whether to search binary files.";
18041809
default = false;
18051810
};
1811+
18061812
color =
18071813
mkOption {
18081814
type = types.enum [ "auto" "always" "never" ];
18091815
description = "When to use generate output.";
18101816
default = "auto";
18111817
};
1812-
configuration =
1813-
mkOption {
1814-
type = types.str;
1815-
description = "Multiline-string configuration passed as config file. If set, config set in `typos.settings.configPath` gets ignored.";
1816-
default = "";
1817-
example = ''
1818-
[files]
1819-
ignore-dot = true
1820-
1821-
[default]
1822-
binary = false
18231818

1824-
[type.py]
1825-
extend-glob = []
1826-
'';
1819+
config =
1820+
mkOption {
1821+
type = toml.type;
1822+
description = "Configuration as in https://github.com/crate-ci/typos/blob/master/docs/reference.md.";
1823+
default = { };
1824+
example = {
1825+
files.ignore-dot = true;
1826+
default.binary = false;
1827+
type.py.extend-glob = [ ];
1828+
};
18271829
};
18281830

18291831
configPath =
18301832
mkOption {
18311833
type = types.str;
1832-
description = "Path to a custom config file.";
1834+
description = "Path to a custom config file. Ignored if `typos.settings.config` is set.";
18331835
default = "";
18341836
example = ".typos.toml";
18351837
};
@@ -1843,10 +1845,18 @@ in
18431845

18441846
exclude =
18451847
mkOption {
1846-
type = types.str;
1847-
description = "Ignore files and directories matching the glob.";
1848-
default = "";
1849-
example = "*.nix";
1848+
type = with types; coercedTo str (s: [ s ]) (listOf str);
1849+
description = "Ignore files and directories matching one of the globs.";
1850+
default = [ ];
1851+
example = [ "*.nix" ];
1852+
};
1853+
1854+
force-exclude =
1855+
mkOption {
1856+
type = types.bool;
1857+
description = "Respect excluded files even for paths passed explicitly.";
1858+
default = true;
1859+
example = false;
18501860
};
18511861

18521862
format =
@@ -4027,18 +4037,20 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
40274037
package = tools.typos;
40284038
entry =
40294039
let
4030-
# Concatenate config in config file with section for ignoring words generated from list of words to ignore
4031-
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;
4032-
configFile = builtins.toFile "typos-config.toml" configuration;
4040+
inherit (hooks.typos.settings) config exclude;
4041+
configFile = toml.generate "typos-config.toml" config;
4042+
excludeFlags = lib.concatStringsSep " "
4043+
(lib.map (glob: "--exclude ${glob}") exclude);
40334044
cmdArgs =
40344045
mkCmdArgs
40354046
(with hooks.typos.settings; [
40364047
[ binary "--binary" ]
40374048
[ (color != "auto") "--color ${color}" ]
4038-
[ (configuration != "") "--config ${configFile}" ]
4039-
[ (configPath != "" && configuration == "") "--config ${configPath}" ]
4049+
[ (config != { }) "--config ${configFile}" ]
4050+
[ (configPath != "" && config == { }) "--config ${configPath}" ]
40404051
[ diff "--diff" ]
4041-
[ (exclude != "") "--exclude ${exclude} --force-exclude" ]
4052+
[ (exclude != [ ]) excludeFlags ]
4053+
[ force-exclude "--force-exclude" ]
40424054
[ (format != "long") "--format ${format}" ]
40434055
[ hidden "--hidden" ]
40444056
[ (locale != "en") "--locale ${locale}" ]
@@ -4051,6 +4063,9 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
40514063
]);
40524064
in
40534065
"${hooks.typos.package}/bin/typos ${cmdArgs}";
4066+
settings.config.default.extend-words = lib.mkIf
4067+
(hooks.typos.settings.ignored-words != [ ])
4068+
(lib.genAttrs hooks.typos.settings.ignored-words lib.id);
40544069
types = [ "text" ];
40554070
};
40564071
typstfmt = {

0 commit comments

Comments
 (0)