Skip to content
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

feat(css_semantic): implement rule hierarchy tracking and enhance rule lookup #3746

Merged
merged 5 commits into from
Sep 2, 2024

Conversation

togami2864
Copy link
Contributor

@togami2864 togami2864 commented Aug 31, 2024

Summary

This PR improves the CSS semantic model by implementing a more efficient rule hierarchy tracking system and improving rule lookup.

get_rule_by_range

I added a new public API, get_rule_by_range to the model that can be used in lint rules.

.foo{
  color: red;
  .bar {
    color: blue;
    font-size: 20px;
    .baz {
      color: pink
    }
  }
}
let model = ctx.model();

let range = node.range(); // Consider node as `color: blue` in `.bar`

// Get the rule containing the given range
let rule = model.get_rule_by_range(range);

// See Selectors 
for selector in &rule.selectors {
    // Work with selectors
}

// See other declarations in the same scope
for declaration in &rule.declarations {
    // Work with declarations
}

// Access parent and child rules
if let Some(parent_id) = rule.parent_id {
    let parent_rule = model.get_rule_by_id(parent_id);
    // Work with parent rule
}

for child_id in &rule.child_ids {
    let child_rule = model.get_rule_by_id(*child_id);
    // Work with child rules
}

Test Plan

CI should pass

@togami2864 togami2864 self-assigned this Aug 31, 2024
@github-actions github-actions bot added the L-CSS Language: CSS label Aug 31, 2024
@togami2864 togami2864 changed the title feat(css_semantic): Implement rule hierarchy tracking and enhance rule lookup feat(css_semantic): implement rule hierarchy tracking and enhance rule lookup Aug 31, 2024
Copy link
Member

@chansuke chansuke left a comment

Choose a reason for hiding this comment

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

Thank you for your work and LGTM now

@togami2864 togami2864 merged commit ab43998 into biomejs:main Sep 2, 2024
10 checks passed
@Conaclos Conaclos added the A-Changelog Area: changelog label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog L-CSS Language: CSS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants