forked from numtide/treefmt-nix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbiome.nix
More file actions
131 lines (122 loc) · 2.77 KB
/
Copy pathbiome.nix
File metadata and controls
131 lines (122 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
{
lib,
pkgs,
config,
mkFormatterModule,
...
}:
let
l = lib // builtins;
t = l.types;
p = pkgs;
cfg = config.programs.biome;
biomeVersion = if builtins.match "^1\\." pkgs.biome.version != null then "1.9.4" else "2.1.2";
schemaUrl = "https://biomejs.dev/schemas/${biomeVersion}/schema.json";
schemaSha256s = {
"1.9.4" = "sha256:0yzw4vymwpa7akyq45v7kkb9gp0szs6zfm525zx2vh1d80568dlz";
"2.1.2" = "sha256:07qlk53lja9rsa46b8nv3hqgdzc9mif5r1nwh7i8mrxcqmfp99s2";
};
schemaSha256 = schemaSha256s.${biomeVersion};
ext.js = [
"*.js"
"*.ts"
"*.mjs"
"*.mts"
"*.cjs"
"*.cts"
"*.jsx"
"*.tsx"
"*.d.ts"
"*.d.cts"
"*.d.mts"
];
ext.json = [
"*.json"
"*.jsonc"
];
ext.css = [
"*.css"
];
in
{
meta.maintainers = [ "andrea11" ];
imports = [
(mkFormatterModule {
name = "biome";
args = [
cfg.formatCommand
"--write"
"--no-errors-on-unmatched"
];
includes = ext.js ++ ext.json ++ ext.css;
})
];
options.programs.biome = {
formatCommand = l.mkOption {
type = t.enum [
"format"
"lint"
"check"
];
description = "The command to run Biome with.";
default = "check";
example = "format";
};
formatUnsafe = l.mkOption {
type = t.bool;
description = "Allows to format a document that has unsafe fixes.";
default = false;
};
settings = l.mkOption {
type = t.attrsOf t.anything;
description = "Raw Biome configuration (must conform to Biome JSON schema)";
default = { };
example = {
formatter = {
indentStyle = "space";
lineWidth = 100;
};
javascript = {
formatter = {
quoteStyle = "single";
lineWidth = 120;
};
};
json = {
formatter = {
enabled = false;
};
};
};
};
};
config = l.mkIf cfg.enable {
settings.formatter.biome.options =
let
json = l.toJSON cfg.settings;
jsonFile = p.writeText "biome.json" json;
biomeSchema = builtins.fetchurl {
url = schemaUrl;
sha256 = schemaSha256;
};
validatedConfig =
p.runCommand "validated-biome-config"
{
buildInputs = [
p.check-jsonschema
];
}
''
echo "Validating biome.json against schema ${schemaUrl}..."
export HOME=$TMPDIR
check-jsonschema --schemafile '${biomeSchema}' '${jsonFile}'
cp '${jsonFile}' $out
'';
in
[
"--config-path"
(l.toString validatedConfig)
]
++ l.optional cfg.formatUnsafe "--unsafe";
};
}