-
-
Notifications
You must be signed in to change notification settings - Fork 721
feat(css_semantic): build semantic model for css #3546
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
Conversation
CodSpeed Performance ReportMerging #3546 will not alter performanceComparing Summary
|
f21a2fe
to
96c9fc3
Compare
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Default)] | ||
pub struct Specificity(pub u32, pub u32, pub u32); |
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.
We should document what are these tree numbers and how they affect the specificity
pub(crate) struct SemanticModelData { | ||
pub(crate) root: CssRoot, | ||
// Map to each by its range | ||
pub(crate) node_by_range: FxHashMap<TextRange, CssSyntaxNode>, | ||
pub(crate) rules: Vec<Rule>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Rule { | ||
pub selectors: Vec<Selector>, | ||
pub declarations: Vec<Declaration>, | ||
pub children: Vec<Rule>, | ||
pub range: TextRange, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Declaration { | ||
pub property: String, | ||
pub value: String, | ||
pub property_range: TextRange, | ||
pub value_range: TextRange, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Selector { | ||
pub name: String, | ||
pub range: TextRange, | ||
pub specificity: Specificity, | ||
} |
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.
We should document all these types
if let Some(property) = node.first_child() { | ||
if let Some(property_name) = property.first_child() { | ||
if let Some(value) = property_name.next_sibling() { |
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.
We can reduce these three Some
into one:
if let Some(value) = node.first_child()
.and_then(|p| p.first_child())
.and_then(|p| p.next_sibling()) {
}
crates/biome_css_semantic/Cargo.toml
Outdated
[package] | ||
authors.workspace = true | ||
categories.workspace = true | ||
description = "<DESCRIPTION>" |
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.
Description missing
1161edb
to
40425e8
Compare
f67de29
to
a3c2f86
Compare
Summary
This PR introduces the semantic model for css. The first usecase might be these linter rules.
stylelint/declaration-block-no-duplicate-properties
#2784I'll try to supprt more cases and integrate the analyzer in another PR later.
Example
Playground
Test Plan
CI should pass