Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl RecessOrderMember {
AnyCssDeclarationOrRule::CssBogus(_) => NodeKindOrder::UnknownKind,
AnyCssDeclarationOrRule::CssMetavariable(_) => NodeKindOrder::UnknownKind,
AnyCssDeclarationOrRule::ScssDeclaration(_) => NodeKindOrder::UnknownKind,
AnyCssDeclarationOrRule::ScssNestingDeclaration(_) => NodeKindOrder::UnknownKind,
AnyCssDeclarationOrRule::AnyCssRule(rule) => match rule {
AnyCssRule::CssAtRule(_) => NodeKindOrder::NestedRuleOrAtRule,
AnyCssRule::CssBogusRule(_) => NodeKindOrder::UnknownKind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ impl Rule for NoUnknownFunction {

fn run(ctx: &RuleContext<Self>) -> Option<Self::State> {
let node = ctx.query();
let binding = node.name().ok()?.value_token().ok()?;
let binding = node.name().ok().and_then(|name| {
name.as_css_identifier()
.and_then(|name| name.value_token().ok())
})?;
let function_name = binding.text_trimmed();

// We don't have a semantic model yet, so we can't determine if functions are defined elsewhere.
Expand Down
10 changes: 5 additions & 5 deletions crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ impl Rule for NoUnknownUnit {
match ancestor.kind() {
CssSyntaxKind::CSS_FUNCTION => {
let function_name_token = ancestor
.cast::<CssFunction>()?
.name()
.ok()?
.value_token()
.ok()?;
.cast::<CssFunction>()?
.name()
.ok()?
.as_css_identifier()
.and_then(|name| name.value_token().ok())?;
Comment on lines 117 to +122
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's examine the actual file and context
cd crates/biome_css_analyze && head -180 src/lint/correctness/no_unknown_unit.rs | tail -80

Repository: biomejs/biome

Length of output: 4311


🏁 Script executed:

# Check the full context of the run function and how the match statement works
sed -n '100,160p' crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs

Repository: biomejs/biome

Length of output: 3573


🏁 Script executed:

# Search for test files that might test SCSS qualified functions
find crates/biome_css_analyze/tests -type f -name "*.rs" | head -5

Repository: biomejs/biome

Length of output: 146


🏁 Script executed:

# Look for any test data or fixtures with image-set or math functions
rg -r 'image-set|math\.' --type-add 'test:tests/**' crates/biome_css_analyze/tests/ -l

Repository: biomejs/biome

Length of output: 8983


🏁 Script executed:

cat crates/biome_css_analyze/tests/specs/correctness/noUnknownUnit/valid.css.snap

Repository: biomejs/biome

Length of output: 2719


🏁 Script executed:

cat crates/biome_css_analyze/tests/specs/correctness/noUnknownUnit/invalid.css.snap

Repository: biomejs/biome

Length of output: 15920


Code silently skips diagnostics for x unit inside SCSS qualified function names.

When a function name cannot be cast to CssIdentifier (e.g. math.image-set(1x)), the ? operator returns None from run() entirely, suppressing diagnostics. This permissive behaviour avoids false positives, but it also skips checking any remaining ancestors in the loop—meaning x inside any unrecognised SCSS qualified function goes unchecked.

No tests currently cover SCSS qualified functions, so the intended behaviour here is unclear. If this is intentional, add a comment to document it; if not, use continue instead of the early return.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_css_analyze/src/lint/correctness/no_unknown_unit.rs` around
lines 117 - 122, The current code in run() uses the ? operator when extracting
function_name_token from
ancestor.cast::<CssFunction>()?.name().ok()?.as_css_identifier().and_then(...),
which causes run() to return early and silently skip diagnostics for units
inside SCSS qualified functions (e.g., math.image-set), so either document that
behaviour or change the early-return to skip this ancestor and continue
scanning; specifically, modify the extraction around
ancestor.cast::<CssFunction>() and the subsequent .name()/as_css_identifier()
chain (the function_name_token logic) to handle failures with a match/if-let and
use continue when the cast/name/identifier is absent, or add a clear comment
above the block explaining that missing/unknown function identifiers are
intentionally ignored.

let function_name = function_name_token
.text_trimmed()
.to_ascii_lowercase_cow();
Expand Down
46 changes: 44 additions & 2 deletions crates/biome_css_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 101 additions & 2 deletions crates/biome_css_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/biome_css_formatter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ biome_suppression = { workspace = true }
[dev-dependencies]
biome_configuration = { path = "../biome_configuration" }
biome_css_parser = { path = "../biome_css_parser" }
biome_css_syntax = { path = "../biome_css_syntax", features = ["scss"] }
biome_formatter = { workspace = true, features = ["countme"] }
biome_formatter_test = { path = "../biome_formatter_test" }
biome_fs = { path = "../biome_fs" }
Expand Down
15 changes: 15 additions & 0 deletions crates/biome_css_formatter/src/css/any/bracketed_value_item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file.

use crate::prelude::*;
use biome_css_syntax::AnyCssBracketedValueItem;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatAnyCssBracketedValueItem;
impl FormatRule<AnyCssBracketedValueItem> for FormatAnyCssBracketedValueItem {
type Context = CssFormatContext;
fn fmt(&self, node: &AnyCssBracketedValueItem, f: &mut CssFormatter) -> FormatResult<()> {
match node {
AnyCssBracketedValueItem::AnyCssCustomIdentifier(node) => node.format().fmt(f),
AnyCssBracketedValueItem::CssGenericDelimiter(node) => node.format().fmt(f),
}
}
}
1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/css/any/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl FormatRule<AnyCssDeclaration> for FormatAnyCssDeclaration {
AnyCssDeclaration::CssDeclarationWithSemicolon(node) => node.format().fmt(f),
AnyCssDeclaration::CssEmptyDeclaration(node) => node.format().fmt(f),
AnyCssDeclaration::ScssDeclaration(node) => node.format().fmt(f),
AnyCssDeclaration::ScssNestingDeclaration(node) => node.format().fmt(f),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ impl FormatRule<AnyCssDeclarationOrAtRule> for FormatAnyCssDeclarationOrAtRule {
AnyCssDeclarationOrAtRule::CssDeclarationWithSemicolon(node) => node.format().fmt(f),
AnyCssDeclarationOrAtRule::CssEmptyDeclaration(node) => node.format().fmt(f),
AnyCssDeclarationOrAtRule::ScssDeclaration(node) => node.format().fmt(f),
AnyCssDeclarationOrAtRule::ScssNestingDeclaration(node) => node.format().fmt(f),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl FormatRule<AnyCssDeclarationOrRule> for FormatAnyCssDeclarationOrRule {
AnyCssDeclarationOrRule::CssEmptyDeclaration(node) => node.format().fmt(f),
AnyCssDeclarationOrRule::CssMetavariable(node) => node.format().fmt(f),
AnyCssDeclarationOrRule::ScssDeclaration(node) => node.format().fmt(f),
AnyCssDeclarationOrRule::ScssNestingDeclaration(node) => node.format().fmt(f),
}
}
}
1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/css/any/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ impl FormatRule<AnyCssExpression> for FormatAnyCssExpression {
AnyCssExpression::CssCommaSeparatedValue(node) => node.format().fmt(f),
AnyCssExpression::CssListOfComponentValuesExpression(node) => node.format().fmt(f),
AnyCssExpression::CssParenthesizedExpression(node) => node.format().fmt(f),
AnyCssExpression::CssUnaryExpression(node) => node.format().fmt(f),
}
}
}
15 changes: 15 additions & 0 deletions crates/biome_css_formatter/src/css/any/function_name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file.

use crate::prelude::*;
use biome_css_syntax::AnyCssFunctionName;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatAnyCssFunctionName;
impl FormatRule<AnyCssFunctionName> for FormatAnyCssFunctionName {
type Context = CssFormatContext;
fn fmt(&self, node: &AnyCssFunctionName, f: &mut CssFormatter) -> FormatResult<()> {
match node {
AnyCssFunctionName::CssIdentifier(node) => node.format().fmt(f),
AnyCssFunctionName::ScssQualifiedName(node) => node.format().fmt(f),
}
}
}
2 changes: 2 additions & 0 deletions crates/biome_css_formatter/src/css/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub(crate) mod attr_name;
pub(crate) mod attr_type;
pub(crate) mod attr_unit;
pub(crate) mod attribute_matcher_value;
pub(crate) mod bracketed_value_item;
pub(crate) mod composes_import_source;
pub(crate) mod compound_selector;
pub(crate) mod conditional_block;
Expand All @@ -32,6 +33,7 @@ pub(crate) mod font_family_name;
pub(crate) mod font_feature_values_block;
pub(crate) mod font_feature_values_item;
pub(crate) mod function;
pub(crate) mod function_name;
pub(crate) mod function_parameter;
pub(crate) mod generic_component_value;
pub(crate) mod if_branch;
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_css_formatter/src/css/any/page_at_rule_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ impl FormatRule<AnyCssPageAtRuleItem> for FormatAnyCssPageAtRuleItem {
AnyCssPageAtRuleItem::CssDeclarationWithSemicolon(node) => node.format().fmt(f),
AnyCssPageAtRuleItem::CssEmptyDeclaration(node) => node.format().fmt(f),
AnyCssPageAtRuleItem::CssMarginAtRule(node) => node.format().fmt(f),
AnyCssPageAtRuleItem::ScssDeclaration(node) => node.format().fmt(f),
AnyCssPageAtRuleItem::ScssNestingDeclaration(node) => node.format().fmt(f),
}
}
}
1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/css/any/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl FormatRule<AnyCssValue> for FormatAnyCssValue {
AnyCssValue::CssString(node) => node.format().fmt(f),
AnyCssValue::CssUnicodeRange(node) => node.format().fmt(f),
AnyCssValue::ScssIdentifier(node) => node.format().fmt(f),
AnyCssValue::ScssQualifiedName(node) => node.format().fmt(f),
AnyCssValue::TwValueThemeReference(node) => node.format().fmt(f),
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/css/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub(crate) mod syntax_component_without_multiplier;
pub(crate) mod syntax_multiplier;
pub(crate) mod syntax_type;
pub(crate) mod type_function;
pub(crate) mod unary_expression;
pub(crate) mod unicode_codepoint;
pub(crate) mod unicode_range;
pub(crate) mod unicode_range_interval;
Expand Down
18 changes: 18 additions & 0 deletions crates/biome_css_formatter/src/css/auxiliary/unary_expression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::prelude::*;
use biome_css_syntax::{CssUnaryExpression, CssUnaryExpressionFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssUnaryExpression;
impl FormatNodeRule<CssUnaryExpression> for FormatCssUnaryExpression {
fn fmt_fields(&self, node: &CssUnaryExpression, f: &mut CssFormatter) -> FormatResult<()> {
let CssUnaryExpressionFields {
operator,
expression,
} = node.as_fields();
let operator = operator?;
let expression = expression?;

write!(f, [operator.format(), expression.format()])
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::prelude::*;
use crate::utils::component_value_list::write_component_value_list;
use biome_css_syntax::CssBracketedValueList;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssBracketedValueList;
impl FormatRule<CssBracketedValueList> for FormatCssBracketedValueList {
type Context = CssFormatContext;
fn fmt(&self, node: &CssBracketedValueList, f: &mut CssFormatter) -> FormatResult<()> {
f.join_with(&space())
.entries(node.iter().formatted())
.finish()
write_component_value_list(node, f)
}
}
Loading
Loading