From e4eba37a68d50179ff5af1705a54d5fd508f7bd5 Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Wed, 5 Jun 2024 14:48:47 +0100 Subject: [PATCH 1/2] feat: add yamlfmt --- README.md | 1 + modules/hooks.nix | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/README.md b/README.md index 8c48c5c9..d0c17900 100644 --- a/README.md +++ b/README.md @@ -304,6 +304,7 @@ clang-format supports. - [check-yaml](https://github.com/pre-commit/pre-commit-hooks/blob/main/pre_commit_hooks/check_yaml.py) - [sort-simple-yaml](https://github.com/pre-commit/pre-commit-hooks/blob/main/pre_commit_hooks/sort_simple_yaml.py) +- [yamlfmt](https://github.com/google/yamlfmt) - [yamllint](https://github.com/adrienverge/yamllint) ### TOML diff --git a/modules/hooks.nix b/modules/hooks.nix index d4b73d09..5590f3ab 100644 --- a/modules/hooks.nix +++ b/modules/hooks.nix @@ -1601,6 +1601,25 @@ in }; }; }; + yamlfmt = mkOption { + description = lib.mdDoc "yamlfmt hook"; + type = types.submodule { + imports = [ hookModule ]; + options.settings = { + configPath = + mkOption { + type = types.str; + description = lib.mdDoc "Path to a custom configuration file."; + # An empty string translates to yamlfmt looking for a configuration file in the + # following locations (by order of preference): + # a file named .yamlfmt, yamlfmt.yml, yamlfmt.yaml, .yamlfmt.yaml or .yamlfmt.yml in the current working directory + # See details [here](https://github.com/google/yamlfmt/blob/main/docs/config-file.md#config-file-discovery) + default = ""; + example = ".yamlfmt"; + }; + }; + }; + }; yamllint = mkOption { description = lib.mdDoc "yamllint hook"; type = types.submodule { @@ -3413,6 +3432,27 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.ormol "${hooks.vale.package}/bin/vale${cmdArgs} ${hooks.vale.settings.flags}"; types = [ "text" ]; }; + yamlfmt = + { + name = "yamlfmt"; + description = "Formatter for YAML files."; + types = [ "file" "yaml" ]; + package = tools.yamlfmt; + entry = + let + cmdArgs = + mkCmdArgs + (with hooks.yamlfmt.settings; [ + # Exit non-zero on changes + [ true "-lint" ] + # But do not print the diff + [ true "-quiet" ] + # See https://github.com/google/yamlfmt/blob/main/docs/config-file.md#config-file-discovery + [ (configPath != "") "-conf ${configPath}" ] + ]); + in + "${hooks.yamlfmt.package}/bin/yamlfmt ${cmdArgs}"; + }; yamllint = { name = "yamllint"; From d74bff580363f769289a4b4938d30555433b858f Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Thu, 6 Jun 2024 02:03:38 +1000 Subject: [PATCH 2/2] fix: update tools.nix to include yamlfmt --- nix/tools.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nix/tools.nix b/nix/tools.nix index bb9549f4..a04dc1bf 100644 --- a/nix/tools.nix +++ b/nix/tools.nix @@ -72,6 +72,7 @@ , typos , typstfmt , zprint +, yamlfmt , yamllint , go , go-tools @@ -146,6 +147,7 @@ in typos typstfmt vale + yamlfmt yamllint zprint ;