diff --git a/README.md b/README.md index df580252..bfd84062 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,7 @@ functions. -`treefmt-nix` currently supports 120 formatters: +`treefmt-nix` currently supports 121 formatters: * [actionlint](programs/actionlint.nix) * [aiken](programs/aiken.nix) @@ -340,6 +340,7 @@ functions. * [typstyle](programs/typstyle.nix) * [xmllint](programs/xmllint.nix) * [yamlfmt](programs/yamlfmt.nix) +* [yamllint](programs/yamllint.nix) * [yapf](programs/yapf.nix) * [zig](programs/zig.nix) * [zizmor](programs/zizmor.nix) diff --git a/examples/formatter-yamllint.toml b/examples/formatter-yamllint.toml new file mode 100644 index 00000000..84983658 --- /dev/null +++ b/examples/formatter-yamllint.toml @@ -0,0 +1,6 @@ +# Example generated by ../examples.sh +[formatter.yamllint] +command = "yamllint" +excludes = [] +includes = ["*.yaml", "*.yml"] +options = [] diff --git a/programs/yamllint.nix b/programs/yamllint.nix new file mode 100644 index 00000000..d0e7cf2d --- /dev/null +++ b/programs/yamllint.nix @@ -0,0 +1,46 @@ +{ + lib, + pkgs, + config, + mkFormatterModule, + ... +}: +let + cfg = config.programs.yamllint; + settingsFormat = pkgs.formats.yaml { }; +in +{ + meta.maintainers = [ + "DigitalBrewStudios/Treefmt-nix" + ]; + + imports = [ + (mkFormatterModule { + name = "yamllint"; + includes = [ + "*.yaml" + "*.yml" + ]; + }) + ]; + + options.programs.yamllint = { + settings = lib.mkOption { + type = lib.types.submodule { freeformType = settingsFormat.type; }; + default = { }; + description = '' + Configuration for yamllint, see + + for supported values. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + settings.formatter.yamllint = { + options = lib.optional ( + cfg.settings != { } + ) "-c=${settingsFormat.generate "yamllint.yaml" cfg.settings}"; + }; + }; +}