languages: allow listOf format.type

This commit is contained in:
Ching Pei Yang 2025-08-23 16:04:51 +02:00
commit 60004b0da2
No known key found for this signature in database
GPG key ID: B3841364253DC4C8
24 changed files with 314 additions and 355 deletions

View file

@ -173,18 +173,18 @@
'';
# TODO: specify packages
defaultFormat = "prettier";
defaultFormat = ["prettier"];
formats = {
prettier = {
package = pkgs.prettier;
command = getExe pkgs.prettier;
};
prettierd = {
package = pkgs.prettierd;
command = getExe pkgs.prettierd;
};
biome = {
package = pkgs.biome;
command = getExe pkgs.biome;
};
};
@ -236,15 +236,9 @@ in {
type = mkOption {
description = "Typescript/Javascript formatter to use";
type = enum (attrNames formats);
type = singleOrListOf (enum (attrNames formats));
default = defaultFormat;
};
package = mkOption {
description = "Typescript/Javascript formatter package";
type = package;
default = formats.${cfg.format.type}.package;
};
};
extraDiagnostics = {
@ -306,12 +300,15 @@ in {
vim.formatter.conform-nvim = {
enable = true;
setupOpts = {
formatters_by_ft.typescript = [cfg.format.type];
formatters_by_ft.typescript = cfg.format.type;
# .tsx files
formatters_by_ft.typescriptreact = [cfg.format.type];
formatters.${cfg.format.type} = {
command = getExe cfg.format.package;
};
formatters_by_ft.typescriptreact = cfg.format.type;
setupOpts.formatters =
mapListToAttrs (name: {
inherit name;
value = formats.${name};
})
cfg.format.type;
};
};
})