Skip to content

typos improvements #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 39 additions & 25 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ let
cfg = config;
inherit (lib) flatten mapAttrs mapAttrsToList mkDefault mkOption mkRemovedOptionModule mkRenamedOptionModule types;

toml = pkgs.formats.toml { };

cargoManifestPathArg =
lib.optionalString
(settings.rust.cargoManifestPath != null)
Expand Down Expand Up @@ -33,6 +35,9 @@ in
(mkRemovedOptionModule [ "settings" "yamllint" "relaxed" ] ''
This option has been removed. Use `hooks.yamllint.settings.preset = "relaxed"`.
'')
(mkRemovedOptionModule [ "typos" "settings" "configuration" ] ''
This option has been removed. Use `hooks.typos.settings.config`, which is a structured attrs, instead.
'')
]
# Manually rename options that had a package or a config option
++ flatten (mapAttrsToList (name: map (o: mkRenamedOptionModule [ "settings" name o ] [ "hooks" name "settings" o ])) {
Expand Down Expand Up @@ -1789,33 +1794,30 @@ in
description = "Whether to search binary files.";
default = false;
};

color =
mkOption {
type = types.enum [ "auto" "always" "never" ];
description = "When to use generate output.";
default = "auto";
};
configuration =
mkOption {
type = types.str;
description = "Multiline-string configuration passed as config file. If set, config set in `typos.settings.configPath` gets ignored.";
default = "";
example = ''
[files]
ignore-dot = true

[default]
binary = false

[type.py]
extend-glob = []
'';
config =
mkOption {
type = toml.type;
description = "Configuration as in https://github.com/crate-ci/typos/blob/master/docs/reference.md.";
default = { };
example = {
files.ignore-dot = true;
default.binary = false;
type.py.extend-glob = [ ];
};
};

configPath =
mkOption {
type = types.str;
description = "Path to a custom config file.";
description = "Path to a custom config file. Ignored if `typos.settings.config` is set.";
default = "";
example = ".typos.toml";
};
Expand All @@ -1829,10 +1831,18 @@ in

exclude =
mkOption {
type = types.str;
description = "Ignore files and directories matching the glob.";
default = "";
example = "*.nix";
type = with types; coercedTo str (s: [ s ]) (listOf str);
description = "Ignore files and directories matching one of the globs.";
default = [ ];
example = [ "*.nix" ];
};

force-exclude =
mkOption {
type = types.bool;
description = "Respect excluded files even for paths passed explicitly.";
default = true;
example = false;
};

format =
Expand Down Expand Up @@ -3988,18 +3998,19 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
package = tools.typos;
entry =
let
# Concatenate config in config file with section for ignoring words generated from list of words to ignore
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;
configFile = builtins.toFile "typos-config.toml" configuration;
inherit (hooks.typos.settings) config exclude;
configFile = toml.generate "typos-config.toml" config;
excludeFlags = lib.map (glob: "--exclude ${glob}") exclude;
cmdArgs =
mkCmdArgs
(with hooks.typos.settings; [
[ binary "--binary" ]
[ (color != "auto") "--color ${color}" ]
[ (configuration != "") "--config ${configFile}" ]
[ (configPath != "" && configuration == "") "--config ${configPath}" ]
[ (config != { }) "--config ${configFile}" ]
[ (configPath != "" && config == { }) "--config ${configPath}" ]
[ diff "--diff" ]
[ (exclude != "") "--exclude ${exclude} --force-exclude" ]
([ (exclude != [ ]) ] ++ excludeFlags)
[ force-exclude " --force-exclude" ]
[ (format != "long") "--format ${format}" ]
[ hidden "--hidden" ]
[ (locale != "en") "--locale ${locale}" ]
Expand All @@ -4012,6 +4023,9 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
]);
in
"${hooks.typos.package}/bin/typos ${cmdArgs}";
settings.config.default.extend-words = lib.mkIf
(hooks.typos.settings.ignored-words != [ ])
(lib.genAttrs hooks.typos.settings.ignored-words lib.id);
types = [ "text" ];
};
typstfmt = {
Expand Down