Skip to content

Commit

Permalink
Merge pull request #453 from joscha/joscha/add-yamlfmt
Browse files Browse the repository at this point in the history
feat: add yamlfmt
  • Loading branch information
domenkozar authored Jun 6, 2024
2 parents 0e8fcc5 + d74bff5 commit cc4d466
Show file tree
Hide file tree
Showing 3 changed files with 43 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
2 changes: 2 additions & 0 deletions nix/tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
, typos
, typstfmt
, zprint
, yamlfmt
, yamllint
, go
, go-tools
Expand Down Expand Up @@ -146,6 +147,7 @@ in
typos
typstfmt
vale
yamlfmt
yamllint
zprint
;
Expand Down

0 comments on commit cc4d466

Please sign in to comment.