languages: allow listOf format.type

This commit is contained in:
Ching Pei Yang 2025-08-23 16:04:51 +02:00
commit 70555904a0
No known key found for this signature in database
GPG key ID: B3841364253DC4C8
22 changed files with 265 additions and 357 deletions

View file

@ -176,18 +176,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;
};
};
@ -239,15 +239,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 = {
@ -309,12 +303,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;
};
};
})