Skip to content

Commit 4927ea4

Browse files
author
subotac
committed
test(lint/css): move Vue deep coverage to rule
1 parent f79d70c commit 4927ea4

6 files changed

Lines changed: 50 additions & 116 deletions

File tree

crates/biome_cli/tests/cases/handle_vue_files.rs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -400,56 +400,6 @@ fn lint_vue_ts_files() {
400400
));
401401
}
402402

403-
#[test]
404-
fn lint_vue_deep_pseudo_class() {
405-
let fs = MemoryFileSystem::default();
406-
let mut console = BufferConsole::default();
407-
408-
fs.insert(
409-
"biome.json".into(),
410-
r#"{ "html": { "linter": {"enabled": true}, "experimentalFullSupportEnabled": true } }"#
411-
.as_bytes(),
412-
);
413-
414-
let vue_file_path = Utf8Path::new("file.vue");
415-
fs.insert(
416-
vue_file_path.into(),
417-
r#"<template>
418-
<div class="parent"><span class="child" /></div>
419-
</template>
420-
421-
<style scoped>
422-
.parent :deep(.child) {}
423-
.parent :unknown {}
424-
</style>
425-
"#
426-
.as_bytes(),
427-
);
428-
429-
let (fs, result) = run_cli(
430-
fs,
431-
&mut console,
432-
Args::from(
433-
[
434-
"lint",
435-
"--only=correctness/noUnknownPseudoClass",
436-
vue_file_path.as_str(),
437-
]
438-
.as_slice(),
439-
),
440-
);
441-
442-
assert!(result.is_err(), "run_cli returned {result:?}");
443-
444-
assert_cli_snapshot(SnapshotPayload::new(
445-
module_path!(),
446-
"lint_vue_deep_pseudo_class",
447-
fs,
448-
console,
449-
result,
450-
));
451-
}
452-
453403
#[test]
454404
fn sorts_imports_check() {
455405
let fs = MemoryFileSystem::default();

crates/biome_cli/tests/snapshots/main_cases_handle_vue_files/lint_vue_deep_pseudo_class.snap

Lines changed: 0 additions & 63 deletions
This file was deleted.

crates/biome_css_analyze/src/lint/correctness/no_unknown_pseudo_class.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ impl Rule for NoUnknownPseudoClass {
214214
if is_valid_class
215215
|| should_ignore(lower_name, ctx.options())
216216
|| file_source.is_css_modules() && is_css_module_pseudo_class(lower_name)
217+
// Vue uses `:deep()` to apply scoped styles to child components.
218+
// https://vuejs.org/api/sfc-css-features.html#deep-selectors
217219
|| file_source.is_vue_embedded() && lower_name == "deep"
218220
{
219221
None

crates/biome_css_analyze/tests/spec_tests.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ use biome_analyze::{
33
Queryable, RegistryVisitor, Rule, RuleDomain, RuleFilter, RuleGroup,
44
};
55
use biome_css_analyze::CssAnalyzerServices;
6-
use biome_css_parser::{CssParserOptions, parse_css};
6+
use biome_css_parser::{CssModulesKind, CssParserOptions, parse_css};
77
use biome_css_semantic::semantic_model;
88
use biome_css_syntax::CssLanguage;
99
use biome_diagnostics::advice::CodeSuggestionAdvice;
1010
use biome_fs::OsFileSystem;
11-
use biome_languages::CssFileSource;
11+
use biome_languages::{
12+
CssFileSource,
13+
css::{CssEmbeddingKind, EmbeddingHtmlKind, EmbeddingStyleApplicability},
14+
};
1215
use biome_plugin_loader::AnalyzerGritPlugin;
1316
use biome_rowan::AstNode;
1417
use biome_test_utils::{
@@ -118,7 +121,18 @@ fn run_test(input: &'static str, _: &str, _: &str, _: &str) {
118121
return;
119122
};
120123

121-
let parser_options = parser_options.unwrap_or(CssParserOptions::from(&source_type));
124+
if file_name.contains(".vue.") && file_name.ends_with(".css") {
125+
source_type =
126+
source_type.with_embedding_kind(CssEmbeddingKind::Html(EmbeddingHtmlKind::Vue {
127+
applicability: EmbeddingStyleApplicability::Local,
128+
}));
129+
}
130+
131+
let mut parser_options = parser_options.unwrap_or(CssParserOptions::from(&source_type));
132+
133+
if source_type.is_vue_embedded() {
134+
parser_options.css_modules = CssModulesKind::Vue;
135+
}
122136

123137
if parser_options.tailwind_directives {
124138
source_type = source_type.with_tailwind_directives()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* should generate diagnostics */
2+
.parent :deep(.child) {}
3+
.parent :unknown {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
source: crates/biome_css_analyze/tests/spec_tests.rs
3+
expression: invalid.vue.css
4+
---
5+
# Input
6+
```css
7+
/* should generate diagnostics */
8+
.parent :deep(.child) {}
9+
.parent :unknown {}
10+
11+
```
12+
13+
# Diagnostics
14+
```
15+
invalid.vue.css:3:10 lint/correctness/noUnknownPseudoClass ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
16+
17+
× Unexpected unknown pseudo-class unknown
18+
19+
1 │ /* should generate diagnostics */
20+
2 │ .parent :deep(.child) {}
21+
> 3 │ .parent :unknown {}
22+
│ ^^^^^^^
23+
4 │
24+
25+
i See MDN web docs for more details.
26+
27+
28+
```

0 commit comments

Comments
 (0)