Skip to content

Commit

Permalink
feat: add yamlfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
joscha committed Jun 5, 2024
1 parent 0e8fcc5 commit e4eba37
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit e4eba37

Please sign in to comment.