-
-
Notifications
You must be signed in to change notification settings - Fork 794
fix(useGenericFontNames): handle CSS variable as last font-family value #8443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(useGenericFontNames): handle CSS variable as last font-family value #8443
Conversation
🦋 Changeset detectedLatest commit: 8f9d71c The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
|
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 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. ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
WalkthroughThis PR fixes a false positive in the Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this 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:
collect_font_family_properties(line 188) filters out function values likevar(), so CSS variables never reach here- The new early check (lines 107-109) would have already returned
NoneIf this check is intended for the
fontproperty case, it should be made explicit, and the early check should also apply tofont(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 thefontshorthand property.The new test cases only cover
font-familywith CSS variables. Since the rule also handles thefontshorthand property (as documented on line 25 and shown in the implementation), consider adding test cases likea { 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_variableutility function already performsto_ascii_lowercase_cow()internally (seecrates/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
⛔ Files ignored due to path filters (1)
crates/biome_css_analyze/tests/specs/a11y/useGenericFontNames/valid.css.snapis excluded by!**/*.snapand 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.mdcrates/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.
crates/biome_css_analyze/src/lint/a11y/use_generic_font_names.rs
Outdated
Show resolved
Hide resolved
CodSpeed Performance ReportMerging #8443 will not alter performanceComparing Summary
Footnotes
|
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
a3e71c6 to
8f9d71c
Compare
Summary
Fix false positive when a CSS variable is used as the last value in
font-family.Before (incorrect):
After (correct):
Root Cause
The
collect_font_family_propertiesfunction only collectsCssIdentifierandCssStringvalues, filtering out function values likevar(). 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_variablefunction to check the original properties list before filtering, correctly handling cases where a CSS variable is the last value.Test Plan
valid.css:font-family: "Noto Serif", var(--serif)font-family: Arial, var(--fallback)Closes #8339