Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@tt-a1i
Copy link
Contributor

@tt-a1i tt-a1i commented Dec 14, 2025

Summary

Fix false positive when a CSS variable is used as the last value in font-family.

Before (incorrect):

a { font-family: "Noto Serif", var(--serif); }
/* ❌ Error: Generic font family missing */

After (correct):

a { font-family: "Noto Serif", var(--serif); }
/* ✅ No error - CSS variable is the last value */

Root Cause

The collect_font_family_properties function only collects CssIdentifier and CssString values, filtering out function values like var(). This caused the CSS variable check to fail because it was checking the filtered list instead of the original properties.

Fix

Added is_last_value_css_variable function to check the original properties list before filtering, correctly handling cases where a CSS variable is the last value.

Test Plan

  • Added test cases in valid.css:
    • font-family: "Noto Serif", var(--serif)
    • font-family: Arial, var(--fallback)

Closes #8339

@changeset-bot
Copy link

changeset-bot bot commented Dec 14, 2025

🦋 Changeset detected

Latest commit: 8f9d71c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Linter Area: linter L-CSS Language: CSS labels Dec 14, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 14, 2025

Warning

Rate limit exceeded

@tt-a1i has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 1 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between a3e71c6 and 8f9d71c.

⛔ Files ignored due to path filters (1)
  • crates/biome_css_analyze/tests/specs/a11y/useGenericFontNames/valid.css.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (3)
  • .changeset/fix-use-generic-font-names-css-variable.md (1 hunks)
  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs (2 hunks)
  • crates/biome_css_analyze/tests/specs/a11y/useGenericFontNames/valid.css (1 hunks)

Walkthrough

This PR fixes a false positive in the useGenericFontNames CSS linter rule. When the last value in a font-family declaration is a CSS variable (e.g., font-family: "Noto Serif", var(--serif)), the rule should ignore such declarations. The fix introduces an early escape path by adding an is_last_value_css_variable helper function that detects CSS variables in the final position, integrating this check before font-family processing. A changelog entry and test cases documenting the fix are included.

Possibly related PRs

Suggested labels

A-Linter, L-CSS

Suggested reviewers

  • ematipico
  • dyc3

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: handling CSS variables as the last font-family value in the useGenericFontNames rule.
Description check ✅ Passed The description clearly explains the false positive, root cause, the fix applied, and test cases added, all directly related to the changeset.
Linked Issues check ✅ Passed The PR fully addresses issue #8339 by implementing the is_last_value_css_variable check to correctly ignore font-family declarations when the last value is a CSS variable.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the useGenericFontNames rule's handling of CSS variables; no extraneous modifications detected.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs (1)

126-132: Remove redundant CSS variable check.

For font-family, this check is now redundant because:

  1. collect_font_family_properties (line 188) filters out function values like var(), so CSS variables never reach here
  2. The new early check (lines 107-109) would have already returned None

If this check is intended for the font property case, it should be made explicit, and the early check should also apply to font (see previous comment).

Consider removing lines 126-132 once the early check is applied to both properties.

🧹 Nitpick comments (2)
crates/biome_css_analyze/tests/specs/a11y/useGenericFontNames/valid.css (1)

25-26: Consider adding test coverage for the font shorthand property.

The new test cases only cover font-family with CSS variables. Since the rule also handles the font shorthand property (as documented on line 25 and shown in the implementation), consider adding test cases like a { font: 1em Arial, var(--fallback); } to ensure comprehensive coverage.

crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs (1)

213-213: Remove redundant lowercase conversion.

The is_css_variable utility function already performs to_ascii_lowercase_cow() internally (see crates/biome_css_analyze/src/utils.rs, line 16). Calling it again here allocates unnecessarily.

Apply this diff:

-        .is_some_and(|v| is_css_variable(&v.to_trimmed_text().text().to_ascii_lowercase_cow()))
+        .is_some_and(|v| is_css_variable(&v.to_trimmed_text().text()))
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a392c06 and a3e71c6.

⛔ Files ignored due to path filters (1)
  • crates/biome_css_analyze/tests/specs/a11y/useGenericFontNames/valid.css.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (3)
  • .changeset/fix-use-generic-font-names-css-variable.md (1 hunks)
  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs (2 hunks)
  • crates/biome_css_analyze/tests/specs/a11y/useGenericFontNames/valid.css (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
crates/**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Update inline rustdoc documentation for rules, assists, and their options when adding new features or changing existing features in Rust crates

Files:

  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
.changeset/*.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Write changesets that are concise (1-3 sentences), user-focused, use past tense for actions taken and present tense for Biome behavior, include code examples for rules, and end sentences with periods

Files:

  • .changeset/fix-use-generic-font-names-css-variable.md
🧠 Learnings (13)
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Use the `noUnknown` prefix for rules that report mistyped entities in CSS (e.g., `noUnknownUnit`)

Applied to files:

  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
  • .changeset/fix-use-generic-font-names-css-variable.md
  • crates/biome_css_analyze/tests/specs/a11y/useGenericFontNames/valid.css
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Check if a variable is global before banning it to avoid false positives when the variable is redeclared in local scope; use the semantic model to verify global scope

Applied to files:

  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Framework-specific rules should be named using the `use` or `no` prefix followed by the framework name (e.g., `noVueReservedProps`)

Applied to files:

  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Rules should use the `use` prefix naming convention when the sole intention is to mandate a single concept (e.g., `useValidLang` to enforce valid HTML lang attribute values)

Applied to files:

  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Use the `noUnsafe` prefix for rules that report code leading to runtime failures (e.g., `noUnsafeOptionalChaining`)

Applied to files:

  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Avoid unnecessary string allocations by comparing against `&str` or `TokenText` instead of calling `to_string()` which allocates heap memory

Applied to files:

  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Use the `noUnused` prefix for rules that report unused entities (e.g., `noUnusedVariables`)

Applied to files:

  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Use the `useConsistent` prefix for rules that ensure consistency across the codebase (e.g., `useConsistentArrayType`)

Applied to files:

  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Use the `noConstant` prefix for rules that report computations always evaluated to the same value (e.g., `noConstantMathMinMaxClamp`)

Applied to files:

  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/lint/**/*.rs : Use the `noUndeclared` prefix for rules that report undefined entities (e.g., `noUndeclaredVariables`)

Applied to files:

  • crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Commit rule changes with message format: `feat(biome_<crate>): <ruleName>` to follow Biome's conventional commit style

Applied to files:

  • .changeset/fix-use-generic-font-names-css-variable.md
📚 Learning: 2025-12-12T10:11:05.549Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-12-12T10:11:05.549Z
Learning: Applies to .changeset/*.md : Write changesets that are concise (1-3 sentences), user-focused, use past tense for actions taken and present tense for Biome behavior, include code examples for rules, and end sentences with periods

Applied to files:

  • .changeset/fix-use-generic-font-names-css-variable.md
📚 Learning: 2025-11-27T23:04:02.022Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-11-27T23:04:02.022Z
Learning: Biome linter is designed to work across languages, so rule naming should be generic if potentially implementable for multiple languages, or specific if meant for one language only

Applied to files:

  • .changeset/fix-use-generic-font-names-css-variable.md
🧬 Code graph analysis (1)
crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs (1)
crates/biome_css_analyze/src/utils.rs (1)
  • is_css_variable (16-18)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Documentation
  • GitHub Check: End-to-end tests
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
🔇 Additional comments (1)
.changeset/fix-use-generic-font-names-css-variable.md (1)

1-5: LGTM!

The changeset is concise, user-focused, includes a code example, and follows the required format.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 14, 2025

CodSpeed Performance Report

Merging #8443 will not alter performance

Comparing tt-a1i:fix/use-generic-font-names-css-variable (8f9d71c) with main (a78774b)1

Summary

✅ 29 untouched
⏩ 126 skipped2

Footnotes

  1. No successful run was found on main (a392c06) during the generation of this report, so a78774b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 126 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Fix false positive when a CSS variable is used as the last value in
font-family, e.g. `font-family: "Noto Serif", var(--serif)`.

The issue was that `collect_font_family_properties` filters out function
values like `var()`, so the CSS variable check was not working correctly.

Added `is_last_value_css_variable` to check the original properties list
before filtering.

Closes biomejs#8339
@tt-a1i tt-a1i force-pushed the fix/use-generic-font-names-css-variable branch from a3e71c6 to 8f9d71c Compare December 14, 2025 02:51
@dyc3 dyc3 merged commit c3fa5a1 into biomejs:main Dec 14, 2025
18 checks passed
This was referenced Dec 14, 2025
l0ngvh pushed a commit to l0ngvh/biome that referenced this pull request Dec 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-CSS Language: CSS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 useGenericFontNames with CSS variables

3 participants