nvf/lib/types/custom.nix
Ching Pei Yang d5da1a14c3
languages/formatters: allow multiple formatters (#1103)
* language/python: allow multiple formatters

* package: add prettier-plugin-astro

* language/astro: fix prettier, remove prettierd

* package: add prettier-plugin-svelte

* language/svelte: fix prettier, remove prettierd

* languages: allow listOf format.type

* deprecations: add warnings for removed format options

* ruby: remove unused variable

* nix: fix outdated references to format.package

* docs: update release note

* treewide: warn deprecation in singleOrListOf

* conform: add definitions for setupOpts.formatters
2025-11-16 19:49:21 +01:00

41 lines
1.1 KiB
Nix

{lib}: let
inherit (builtins) warn toJSON;
inherit (lib.options) mergeEqualOption;
inherit (lib.lists) singleton;
inherit (lib.strings) isString stringLength match;
inherit (lib.types) listOf mkOptionType coercedTo;
in {
mergelessListOf = elemType:
mkOptionType {
name = "mergelessListOf";
description = "mergeless list of ${elemType.description or "values"}";
inherit (lib.types.listOf elemType) check;
merge = mergeEqualOption;
};
char = mkOptionType {
name = "char";
description = "character";
descriptionClass = "noun";
check = value: stringLength value < 2;
merge = mergeEqualOption;
};
hexColor = mkOptionType {
name = "hex-color";
descriptionClass = "noun";
description = "RGB color in hex format";
check = v: isString v && (match "#?[0-9a-fA-F]{6}" v) != null;
};
# no compound types please
deprecatedSingleOrListOf = option: t:
coercedTo
t
(x:
warn ''
${option} no longer accepts non-list values, use [${toJSON x}] instead
''
(singleton x))
(listOf t);
}