Skip to content

Commit

Permalink
Merge pull request cachix#333 from totoroot/add-config-option-typos-hook
Browse files Browse the repository at this point in the history
Fix settings and add config option for `typos` hook
  • Loading branch information
domenkozar authored and totoroot committed Aug 4, 2023
2 parents 52bf404 + 046d10f commit 58bd8ed
Showing 1 changed file with 65 additions and 37 deletions.
102 changes: 65 additions & 37 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
};
};
Expand Down Expand Up @@ -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 =
Expand All @@ -293,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;
Expand Down Expand Up @@ -332,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;
};
};
Expand Down Expand Up @@ -495,13 +520,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 = "";
Expand Down Expand Up @@ -560,21 +585,14 @@ in
{
binPath =
mkOption {
type = types.str;
type = types.path;
description = lib.mdDoc "mkdocs-linkcheck binary path. Should be used to specify the mkdocs-linkcheck binary from your Nix-managed Python environment.";
default = "${pkgs.mkdocs-linkcheck}/bin/mkdocs-linkcheck";
default = "${pkgs.python311Packages.sh}/bin/mkdocs-linkcheck";
defaultText = lib.literalExpression ''
"''${pkgs.mkdocs-linkcheck}/bin/mkdocs-linkcheck"
'';
};

path =
mkOption {
type = types.nullOr types.path;
description = lib.mdDoc "Path to check";
default = null;
};

local-only =
mkOption {
type = types.bool;
Expand Down Expand Up @@ -602,14 +620,6 @@ in
description = lib.mdDoc "HTTP method to use when checking external links.";
default = "get";
};

exclude =
mkOption {
type = types.listOf types.str;
description = lib.mdDoc "Pattern for files or paths to exclude";
default = [ ];
example = [ "do-not-check.md" "./archive" ];
};
};

dune-fmt =
Expand Down Expand Up @@ -1162,14 +1172,14 @@ in
entry = "${tools.purs-tidy}/bin/purs-tidy format-in-place";
files = "\\.purs$";
};
prettier =
{
name = "prettier";
description = "Opinionated multi-language code formatter.";
entry = with settings.prettier;
"${binPath} ${lib.optionalString write "--write"} ${lib.optionalString (output != null) "--${output}"} --ignore-unknown";
types = [ "text" ];
};

prettier = {
name = "prettier";
description = "Opinionated multi-language code formatter.";
entry = with settings.prettier;
"${binPath} ${lib.optionalString write "--write"} ${lib.optionalString (output != null) "--${output}"} --ignore-unknown";
types = [ "text" ];
};
pre-commit-hook-ensure-sops = {
name = "pre-commit-hook-ensure-sops";
entry =
Expand Down Expand Up @@ -1223,8 +1233,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" ];
};

Expand Down Expand Up @@ -1586,13 +1610,17 @@ in
mkdocs-linkcheck = {
name = "mkdocs-linkcheck";
description = "Validate links associated with markdown-based, statically generated websites.";
types = [ "text" "markdown" ];
entry =
let
local-only = if settings.mkdocs-linkcheck.local-only then "--local" else "";
recurse = if settings.mkdocs-linkcheck.recurse then "--recurse" else "";
cmdArgs =
mkCmdArgs
(with settings.mkdocs-linkcheck; [
[ (extension != "") "--ext ${extension}" ]
[ (method != "") "--method ${method}" ]
]);
in
"${pkgs.mkdocs-linkcheck}/bin/mkdocs-linkcheck ${local-only} ${recurse} --ext ${settings.mkdocs-linkcheck.extension} --method ${settings.mkdocs-linkcheck.method} --exclude ${settings.mkdocs-linkcheck.exclude} ${settings.mkdocs-linkcheck.path}";
"${settings.mkdocs-linkcheck.binPath} ${cmdArgs}${lib.optionalString settings.mkdocs-linkcheck.local-only " --local"}${lib.optionalString settings.mkdocs-linkcheck.recurse " --recurse"}";
types = [ "text" ];
};

checkmake = {
Expand Down

0 comments on commit 58bd8ed

Please sign in to comment.