Skip to content

Commit 2b2a130

Browse files
committed
Merge remote-tracking branch 'origin/main' into chore/modernize-ci-and-readme
# Conflicts: # scripts/update.ts
2 parents 6fd9dcd + 07e7dfc commit 2b2a130

11 files changed

Lines changed: 130 additions & 59 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Cargo.lock
33
deployment/npm/plugin.wasm
44
deployment/npm/node_modules
55
.vscode
6+
.claude

Cargo.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dprint-plugin-biome"
3-
version = "0.11.9"
3+
version = "0.12.11"
44
authors = ["David Sherret <dsherret@gmail.com>"]
55
edition = "2024"
66
homepage = "https://github.com/dprint/dprint-plugin-biome"
@@ -25,19 +25,19 @@ wasm = ["serde_json", "dprint-core/wasm"]
2525

2626
[dependencies]
2727
anyhow = "1.0.51"
28-
biome_css_formatter = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
29-
biome_css_parser = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
30-
biome_css_syntax = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
31-
biome_diagnostics = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
32-
biome_formatter = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
33-
biome_graphql_formatter = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
34-
biome_graphql_parser = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
35-
biome_graphql_syntax = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
36-
biome_js_formatter = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
37-
biome_js_parser = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
38-
biome_js_syntax = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
39-
biome_json_formatter = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
40-
biome_json_parser = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.3.10" }
28+
biome_css_formatter = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
29+
biome_css_parser = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
30+
biome_css_syntax = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
31+
biome_diagnostics = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
32+
biome_formatter = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
33+
biome_graphql_formatter = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
34+
biome_graphql_parser = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
35+
biome_graphql_syntax = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
36+
biome_js_formatter = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
37+
biome_js_parser = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
38+
biome_js_syntax = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
39+
biome_json_formatter = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
40+
biome_json_parser = { git = "https://github.com/biomejs/biome", tag = "@biomejs/biome@2.4.15" }
4141
camino = "1.1.10"
4242
dprint-core = { version = "0.67.4", default-features = false }
4343
serde = { version = "1.0.210", features = ["derive"] }

deployment/schema.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@
9292
"css.indentStyle": {
9393
"$ref": "#/definitions/indentStyle"
9494
},
95+
"css.cssModules": {
96+
"description": "Enable CSS modules support (enables :local and :global selectors).",
97+
"default": false,
98+
"type": "boolean"
99+
},
100+
"css.gritMetavariables": {
101+
"description": "Enable parsing of GritQL metavariables in CSS. Overrides top-level gritMetavariables.",
102+
"default": false,
103+
"type": "boolean"
104+
},
95105
"graphql.enabled": {
96106
"description": "Enable graphql formatting.",
97107
"default": false,
@@ -131,6 +141,11 @@
131141
"default": true,
132142
"type": "boolean"
133143
},
144+
"javascript.gritMetavariables": {
145+
"description": "Enable parsing of GritQL metavariables in JavaScript/TypeScript. Overrides top-level gritMetavariables.",
146+
"default": false,
147+
"type": "boolean"
148+
},
134149
"json.indentStyle": {
135150
"$ref": "#/definitions/indentStyle"
136151
},
@@ -194,6 +209,11 @@
194209
"description": "Surround the inner contents of some braces with spaces.",
195210
"default": true,
196211
"type": "boolean"
212+
},
213+
"gritMetavariables": {
214+
"description": "Enable parsing of GritQL metavariables.",
215+
"default": false,
216+
"type": "boolean"
197217
}
198218
}
199219
}

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.92.0"
2+
channel = "1.95.0"
33
components = ["clippy", "rustfmt"]

scripts/update.ts

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ if (cargoTomlVersion.tag === latestTag.tag) {
1919
$.log("Found new version.");
2020
$.logStep("Updating rust-toolchain.toml...");
2121
await updateRustToolchain(latestTag.tag);
22-
2322
$.logStep("Updating Cargo.toml...");
2423
const isPatchBump = cargoTomlVersion.version.major === latestTag.version.major
2524
&& cargoTomlVersion.version.minor === latestTag.version.minor;
@@ -82,29 +81,10 @@ function tagToVersion(tag: string) {
8281
return semver.parse(tag.replace(/^@biomejs\/biome@/, ""));
8382
}
8483

85-
async function getGitTags(): Promise<string[]> {
86-
const client = new Octokit();
87-
const tags = await client.paginate("GET /repos/{owner}/{repo}/tags", {
88-
owner: "biomejs",
89-
repo: "biome",
90-
per_page: 100,
91-
});
92-
return tags.map(tag => tag.name);
93-
}
94-
9584
async function updateRustToolchain(tag: string) {
96-
// biome's tag (e.g. "@biomejs/biome@2.3.10") contains "/" and "@",
97-
// both of which need percent-encoding in the raw.githubusercontent.com URL.
98-
const encodedTag = encodeURIComponent(tag);
99-
// .noThrow() so we can branch on 404 instead of throwing.
100-
const response = await $.request(
101-
`https://raw.githubusercontent.com/biomejs/biome/${encodedTag}/rust-toolchain.toml`,
102-
).noThrow();
103-
if (response.status === 404) {
104-
$.log(`biome ${tag} does not include a rust-toolchain.toml; leaving local one alone.`);
105-
return;
106-
}
107-
const content = await response.text();
85+
const content = await $.request(
86+
`https://raw.githubusercontent.com/biomejs/biome/${tag}/rust-toolchain.toml`,
87+
).text();
10888
const match = content.match(/channel\s*=\s*"([^"]+)"/);
10989
if (match == null) {
11090
throw new Error("Could not find channel in biome's rust-toolchain.toml.");
@@ -116,16 +96,21 @@ async function updateRustToolchain(tag: string) {
11696
if (localMatch == null) {
11797
throw new Error("Could not find channel in local rust-toolchain.toml.");
11898
}
119-
// rust-toolchain.toml channels may be just "1.84" (no patch); pad to
120-
// MAJOR.MINOR.PATCH so @std/semver can parse it.
121-
const normalize = (v: string) => /^\d+\.\d+$/.test(v) ? `${v}.0` : v;
122-
// only bump up; never downgrade. compare as semver so 1.95.0 > 1.91.0.
123-
const local = semver.parse(normalize(localMatch[1]));
124-
const upstream = semver.parse(normalize(biomeRustVersion));
125-
if (semver.greaterThan(upstream, local)) {
99+
if (localMatch[1] !== biomeRustVersion) {
126100
$.log(`Updating Rust toolchain: ${localMatch[1]} -> ${biomeRustVersion}`);
127101
toolchainPath.writeTextSync(localContent.replace(localMatch[0], `channel = "${biomeRustVersion}"`));
128102
} else {
129-
$.log(`Rust toolchain at ${localMatch[1]} already satisfies biome ${tag} (needs >= ${biomeRustVersion}).`);
103+
$.log(`Rust toolchain already at ${biomeRustVersion}.`);
130104
}
131105
}
106+
107+
async function getGitTags(): Promise<string[]> {
108+
const client = new Octokit();
109+
const tags = await client.paginate("GET /repos/{owner}/{repo}/tags", {
110+
owner: "biomejs",
111+
repo: "biome",
112+
per_page: 100,
113+
});
114+
return tags.map(tag => tag.name);
115+
}
116+

src/configuration/configuration.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,7 @@ pub struct Configuration {
9696
pub trailing_commas: Option<TrailingComma>,
9797
pub bracket_same_line: Option<bool>,
9898
pub javascript_bracket_spacing: Option<bool>,
99+
pub css_css_modules: Option<bool>,
100+
pub css_grit_metavariables: Option<bool>,
101+
pub javascript_grit_metavariables: Option<bool>,
99102
}

src/configuration/resolve_config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub fn resolve_config(
4747
let quote_style = get_nullable_value(&mut config, "quoteStyle", &mut diagnostics);
4848
let jsx_quote_style = get_nullable_value(&mut config, "jsxQuoteStyle", &mut diagnostics);
4949
let bracket_spacing = get_nullable_value(&mut config, "bracketSpacing", &mut diagnostics);
50+
let grit_metavariables: Option<bool> = get_nullable_value(&mut config, "gritMetavariables", &mut diagnostics);
5051

5152
let resolved_config = Configuration {
5253
line_ending: get_nullable_value(&mut config, "lineEnding", &mut diagnostics).or(
@@ -89,6 +90,11 @@ pub fn resolve_config(
8990
bracket_same_line: get_nullable_value(&mut config, "bracketSameLine", &mut diagnostics),
9091
javascript_bracket_spacing: get_nullable_value(&mut config, "javascript.bracketSpacing", &mut diagnostics)
9192
.or(bracket_spacing),
93+
css_css_modules: get_nullable_value(&mut config, "css.cssModules", &mut diagnostics),
94+
css_grit_metavariables: get_nullable_value(&mut config, "css.gritMetavariables", &mut diagnostics)
95+
.or(grit_metavariables),
96+
javascript_grit_metavariables: get_nullable_value(&mut config, "javascript.gritMetavariables", &mut diagnostics)
97+
.or(grit_metavariables),
9298
};
9399

94100
diagnostics.extend(get_unknown_property_diagnostics(config));

src/format_text.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use anyhow::Result;
22
use anyhow::bail;
33
use biome_css_formatter::context::CssFormatOptions;
4+
use biome_css_parser::CssModulesKind;
45
use biome_css_parser::CssParserOptions;
56
use biome_css_syntax::CssFileSource;
67
use biome_formatter::IndentStyle;
@@ -38,6 +39,7 @@ pub fn format_text(file_path: &Path, input_text: &str, config: &Configuration) -
3839
JsonParserOptions {
3940
allow_comments: true,
4041
allow_trailing_commas: true,
42+
allow_metavariables: config.javascript_grit_metavariables.unwrap_or(false),
4143
},
4244
);
4345
if tree.has_errors() {
@@ -70,13 +72,13 @@ pub fn format_text(file_path: &Path, input_text: &str, config: &Configuration) -
7072
syntax,
7173
JsParserOptions {
7274
parse_class_parameter_decorators: true,
73-
grit_metavariables: false,
75+
grit_metavariables: config.javascript_grit_metavariables.unwrap_or(false),
7476
},
7577
);
7678
if tree.has_errors() {
7779
bail!("{}", get_diagnostics_message(tree.into_diagnostics()));
7880
}
79-
let formatted = biome_js_formatter::format_node(options, &tree.syntax())?;
81+
let formatted = biome_js_formatter::format_node(options, &tree.syntax(), false)?;
8082
formatted.print()?.into_code()
8183
}
8284
Some("css") => {
@@ -93,10 +95,15 @@ pub fn format_text(file_path: &Path, input_text: &str, config: &Configuration) -
9395
let options = build_css_options(config, syntax)?;
9496
let tree = biome_css_parser::parse_css(
9597
input_text,
98+
syntax,
9699
CssParserOptions {
97100
allow_wrong_line_comments: true,
98-
css_modules: true,
99-
grit_metavariables: false,
101+
css_modules: if config.css_css_modules.unwrap_or(false) {
102+
CssModulesKind::Classic
103+
} else {
104+
CssModulesKind::None
105+
},
106+
grit_metavariables: config.css_grit_metavariables.unwrap_or(false),
100107
tailwind_directives: Default::default(),
101108
},
102109
);

tests/specs/CssCssModules.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- file.css --
2+
~~ css.enabled: true, css.cssModules: true ~~
3+
== should format css with modules ==
4+
:local(.className) {
5+
color: red;
6+
}
7+
8+
[expect]
9+
:local(.className) {
10+
color: red;
11+
}

tests/specs/GritMetavariables.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
~~ javascript.gritMetavariables: true ~~
2+
== should format js with metavariables ==
3+
const x = µvar_name
4+
5+
[expect]
6+
const x = µvar_name;

0 commit comments

Comments
 (0)