Skip to content

Commit 72afdfa

Browse files
ematipicosiketyan
andauthored
fix(cli): css parsing arguments for ci command (#7840)
Co-authored-by: siketyan <[email protected]>
1 parent 53ffa8b commit 72afdfa

File tree

7 files changed

+321
-2
lines changed

7 files changed

+321
-2
lines changed

.changeset/afraid-meals-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#7838](https://github.com/biomejs/biome/issues/7838), which caused the new `--css-parse-*` arguments not being recognised by the `ci` command.

crates/biome_cli/src/commands/ci.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ impl CommandRunner for CiCommandPayload {
7878
.json
7979
.get_or_insert_with(JsonConfiguration::default);
8080
if self.json_parser.is_some() {
81-
json.parser.clone_from(&self.json_parser)
81+
json.parser.merge_with(self.json_parser.clone())
8282
}
8383

8484
let css = configuration
8585
.css
8686
.get_or_insert_with(CssConfiguration::default);
8787
if self.css_parser.is_some() {
88-
css.parser.clone_from(&self.css_parser);
88+
css.parser.merge_with(self.css_parser.clone());
8989
}
9090

9191
let assist = configuration

crates/biome_cli/tests/cases/css_parsing.rs

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,60 @@ fn format_css_parse_tailwind_directives_true() {
219219
));
220220
}
221221

222+
#[test]
223+
fn ci_css_parse_css_modules_true() {
224+
let fs = MemoryFileSystem::default();
225+
let mut console = BufferConsole::default();
226+
227+
let file_path = Utf8Path::new("file.module.css");
228+
// CSS Modules specific syntax
229+
fs.insert(
230+
file_path.into(),
231+
".className { composes: other from './other.module.css'; }".as_bytes(),
232+
);
233+
234+
let (fs, result) = run_cli(
235+
fs,
236+
&mut console,
237+
Args::from(["ci", "--css-parse-css-modules=true", file_path.as_str()].as_slice()),
238+
);
239+
240+
assert_cli_snapshot(SnapshotPayload::new(
241+
module_path!(),
242+
"ci_css_parse_css_modules_true",
243+
fs,
244+
console,
245+
result,
246+
));
247+
}
248+
249+
#[test]
250+
fn ci_css_parse_css_modules_false() {
251+
let fs = MemoryFileSystem::default();
252+
let mut console = BufferConsole::default();
253+
254+
let file_path = Utf8Path::new("file.module.css");
255+
// CSS Modules specific syntax
256+
fs.insert(
257+
file_path.into(),
258+
".className { composes: other from './other.module.css'; }".as_bytes(),
259+
);
260+
261+
let (fs, result) = run_cli(
262+
fs,
263+
&mut console,
264+
Args::from(["ci", "--css-parse-css-modules=false", file_path.as_str()].as_slice()),
265+
);
266+
267+
assert_cli_snapshot(SnapshotPayload::new(
268+
module_path!(),
269+
"ci_css_parse_css_modules_false",
270+
fs,
271+
console,
272+
result,
273+
));
274+
}
275+
222276
#[test]
223277
fn ci_css_parse_tailwind_directives_true() {
224278
let fs = MemoryFileSystem::default();
@@ -253,6 +307,76 @@ fn ci_css_parse_tailwind_directives_true() {
253307
));
254308
}
255309

310+
#[test]
311+
fn ci_css_parse_tailwind_directives_false() {
312+
let fs = MemoryFileSystem::default();
313+
let mut console = BufferConsole::default();
314+
315+
let file_path = Utf8Path::new("file.css");
316+
// Tailwind CSS 4.0 directive
317+
fs.insert(
318+
file_path.into(),
319+
"@import 'tailwindcss';\n.foo { color: red; }".as_bytes(),
320+
);
321+
322+
let (fs, result) = run_cli(
323+
fs,
324+
&mut console,
325+
Args::from(
326+
[
327+
"ci",
328+
"--css-parse-tailwind-directives=false",
329+
file_path.as_str(),
330+
]
331+
.as_slice(),
332+
),
333+
);
334+
335+
assert_cli_snapshot(SnapshotPayload::new(
336+
module_path!(),
337+
"ci_css_parse_tailwind_directives_false",
338+
fs,
339+
console,
340+
result,
341+
));
342+
}
343+
344+
#[test]
345+
fn ci_combined_css_parser_flags() {
346+
let fs = MemoryFileSystem::default();
347+
let mut console = BufferConsole::default();
348+
349+
let file_path = Utf8Path::new("file.module.css");
350+
// CSS Modules with Tailwind directives
351+
fs.insert(
352+
file_path.into(),
353+
"@import 'tailwindcss';\n.className { composes: other from './other.module.css'; }"
354+
.as_bytes(),
355+
);
356+
357+
let (fs, result) = run_cli(
358+
fs,
359+
&mut console,
360+
Args::from(
361+
[
362+
"ci",
363+
"--css-parse-css-modules=true",
364+
"--css-parse-tailwind-directives=true",
365+
file_path.as_str(),
366+
]
367+
.as_slice(),
368+
),
369+
);
370+
371+
assert_cli_snapshot(SnapshotPayload::new(
372+
module_path!(),
373+
"ci_combined_css_parser_flags",
374+
fs,
375+
console,
376+
result,
377+
));
378+
}
379+
256380
// Combined tests
257381

258382
#[test]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
expression: redactor(content)
4+
---
5+
## `file.module.css`
6+
7+
```css
8+
@import 'tailwindcss';
9+
.className { composes: other from './other.module.css'; }
10+
```
11+
12+
# Termination Message
13+
14+
```block
15+
ci ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
16+
17+
× Some errors were emitted while running checks.
18+
19+
20+
21+
```
22+
23+
# Emitted Messages
24+
25+
```block
26+
file.module.css format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
27+
28+
× File content differs from formatting output
29+
30+
1 │ - @import·'tailwindcss';
31+
2 │ - .className·{·composesother·from·'./other.module.css'}
32+
1 │ + @import·"tailwindcss";
33+
2 │ + .className·{
34+
3+composesother·from·"./other.module.css";
35+
4+ }
36+
5 │ +
37+
38+
39+
```
40+
41+
```block
42+
Checked 1 file in <TIME>. No fixes applied.
43+
Found 1 error.
44+
```
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
expression: redactor(content)
4+
---
5+
## `file.module.css`
6+
7+
```css
8+
.className { composes: other from './other.module.css'; }
9+
```
10+
11+
# Termination Message
12+
13+
```block
14+
ci ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
15+
16+
× Some errors were emitted while running checks.
17+
18+
19+
20+
```
21+
22+
# Emitted Messages
23+
24+
```block
25+
file.module.css:1:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
26+
27+
× `composes` declaration is not a standard CSS feature.
28+
29+
> 1 │ .className { composes: other from './other.module.css'; }
30+
│ ^^^^^^^^
31+
32+
i You can enable `composes` declaration parsing by setting the `css.parser.cssModules` option to `true` in your configuration file.
33+
34+
35+
```
36+
37+
```block
38+
file.module.css:1:14 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
39+
40+
× `composes` declaration is not a standard CSS feature.
41+
42+
> 1 │ .className { composes: other from './other.module.css'; }
43+
│ ^^^^^^^^
44+
45+
i You can enable `composes` declaration parsing by setting the `css.parser.cssModules` option to `true` in your configuration file.
46+
47+
48+
```
49+
50+
```block
51+
file.module.css format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
52+
53+
× Code formatting aborted due to parsing errors. To format code with errors, enable the 'formatter.formatWithErrors' option.
54+
55+
56+
```
57+
58+
```block
59+
Checked 1 file in <TIME>. No fixes applied.
60+
Found 3 errors.
61+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
expression: redactor(content)
4+
---
5+
## `file.module.css`
6+
7+
```css
8+
.className { composes: other from './other.module.css'; }
9+
```
10+
11+
# Termination Message
12+
13+
```block
14+
ci ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
15+
16+
× Some errors were emitted while running checks.
17+
18+
19+
20+
```
21+
22+
# Emitted Messages
23+
24+
```block
25+
file.module.css format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
26+
27+
× File content differs from formatting output
28+
29+
1 │ - .className·{·composesother·from·'./other.module.css'}
30+
1 │ + .className·{
31+
2+composesother·from·"./other.module.css";
32+
3+ }
33+
4 │ +
34+
35+
36+
```
37+
38+
```block
39+
Checked 1 file in <TIME>. No fixes applied.
40+
Found 1 error.
41+
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
expression: redactor(content)
4+
---
5+
## `file.css`
6+
7+
```css
8+
@import 'tailwindcss';
9+
.foo { color: red; }
10+
```
11+
12+
# Termination Message
13+
14+
```block
15+
ci ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
16+
17+
× Some errors were emitted while running checks.
18+
19+
20+
21+
```
22+
23+
# Emitted Messages
24+
25+
```block
26+
file.css format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
27+
28+
× File content differs from formatting output
29+
30+
1 │ - @import·'tailwindcss';
31+
2 │ - .foo·{·colorred}
32+
1 │ + @import·"tailwindcss";
33+
2 │ + .foo·{
34+
3+colorred;
35+
4+ }
36+
5 │ +
37+
38+
39+
```
40+
41+
```block
42+
Checked 1 file in <TIME>. No fixes applied.
43+
Found 1 error.
44+
```

0 commit comments

Comments
 (0)