Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/skip-supports-feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

fix(css): skip `useGenericFontNames` rule in `@supports` feature declarations
15 changes: 15 additions & 0 deletions crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ declare_lint_rule! {
/// - Property with a keyword value such as `inherit`, `initial`.
/// - The last value being a CSS variable.
/// - `font-family` property in an `@font-face` rule.
/// - Properties inside an `@supports` feature declaration (used for feature testing).
///
/// ## Examples
///
Expand Down Expand Up @@ -88,6 +89,12 @@ impl Rule for UseGenericFontNames {
return None;
}

// Ignore `@supports` feature declarations since they test for browser support,
// not actual font usage. e.g: @supports (font: -apple-system-body) { ... }
if is_in_supports_feature_declaration(node) {
return None;
}

let is_font_family = property_name == "font-family";
let is_font = property_name == "font";

Expand Down Expand Up @@ -158,6 +165,14 @@ fn is_in_font_face_at_rule(node: &CssGenericProperty) -> bool {
.is_some_and(|n| matches!(n, AnyCssAtRule::CssFontFaceAtRule(_)))
}

/// Check if the property is inside an `@supports` feature declaration.
/// Properties in @supports conditions test for browser support, not actual font usage.
fn is_in_supports_feature_declaration(node: &CssGenericProperty) -> bool {
node.syntax()
.ancestors()
.any(|n| n.kind() == CssSyntaxKind::CSS_SUPPORTS_FEATURE_DECLARATION)
}

fn is_shorthand_font_property_with_keyword(properties: &CssGenericComponentValueList) -> bool {
properties.into_iter().len() == 1
&& properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ a { font-family: Arial, var(--fallback); }
a { font: 1em "Noto Serif", var(--serif); }
a { font: 14px/1.5 Arial, var(--fallback); }
a { font-family: revert }
a { font-family: revert-layer }
a { font-family: revert-layer }
@supports (font: -apple-system-body) { }
@supports (font-family: -apple-system) { }
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ a { font: 1em "Noto Serif", var(--serif); }
a { font: 14px/1.5 Arial, var(--fallback); }
a { font-family: revert }
a { font-family: revert-layer }
@supports (font: -apple-system-body) { }
@supports (font-family: -apple-system) { }
```