-
-
Notifications
You must be signed in to change notification settings - Fork 480
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(biome_css_analyzer): implement selector-pseudo-class-no-unknown #3034
feat(biome_css_analyzer): implement selector-pseudo-class-no-unknown #3034
Conversation
CodSpeed Performance ReportMerging #3034 will not alter performanceComparing Summary
|
fn is_webkit_pseudo_class(node: &AnyPseudoLike) -> bool { | ||
let mut prev_element = node.syntax().parent().and_then(|p| p.prev_sibling()); | ||
while let Some(prev) = &prev_element { | ||
let maybe_selector: Option<CssPseudoElementSelector> = prev.clone().cast(); | ||
if let Some(selector) = maybe_selector.as_ref() { | ||
return WEBKIT_SCROLLBAR_PSEUDO_ELEMENTS.contains(&selector.text().trim_matches(':')); | ||
}; | ||
prev_element = prev.prev_sibling(); | ||
} | ||
|
||
false | ||
} |
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.
To determine whether a ::-webkit-scrollbar
CSS pseudo-element has a selector, I'm retrieving each previous element one by one, but I feel there might be a performance issue.
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.
Thank you! I left some suggestions.
declare_node_union! { | ||
pub AnyPseudoLike = CssPseudoClassFunctionCompoundSelector|CssPseudoClassFunctionCompoundSelectorList|CssPseudoClassFunctionIdentifier | ||
|CssPseudoClassFunctionNth|CssPseudoClassFunctionRelativeSelectorList|CssPseudoClassFunctionSelector | ||
|CssPseudoClassFunctionSelectorList|CssPseudoClassFunctionValueList|CssPseudoClassIdentifier | ||
|CssBogusPseudoClass|CssPageSelectorPseudo | ||
} |
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.
declare_node_union! { | |
pub AnyPseudoLike = CssPseudoClassFunctionCompoundSelector|CssPseudoClassFunctionCompoundSelectorList|CssPseudoClassFunctionIdentifier | |
|CssPseudoClassFunctionNth|CssPseudoClassFunctionRelativeSelectorList|CssPseudoClassFunctionSelector | |
|CssPseudoClassFunctionSelectorList|CssPseudoClassFunctionValueList|CssPseudoClassIdentifier | |
|CssBogusPseudoClass|CssPageSelectorPseudo | |
} | |
declare_node_union! { | |
pub AnyPseudoLike = | |
CssPseudoClassFunctionCompoundSelector | |
| CssPseudoClassFunctionCompoundSelectorList | |
| CssPseudoClassFunctionIdentifier | |
| CssPseudoClassFunctionNth | |
| CssPseudoClassFunctionRelativeSelectorList | |
| CssPseudoClassFunctionSelector | |
| CssPseudoClassFunctionSelectorList | |
| CssPseudoClassFunctionValueList | |
| CssPseudoClassIdentifier | |
| CssBogusPseudoClass | |
| CssPageSelectorPseudo | |
} |
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.
Thank you for the suggestions. I fixed it in 8a79444
fn is_webkit_pseudo_class(node: &AnyPseudoLike) -> bool { | ||
let mut prev_element = node.syntax().parent().and_then(|p| p.prev_sibling()); | ||
while let Some(prev) = &prev_element { | ||
let maybe_selector: Option<CssPseudoElementSelector> = prev.clone().cast(); |
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.
let maybe_selector: Option<CssPseudoElementSelector> = prev.clone().cast(); | |
let maybe_selector = CssPseudoElementSelector::cast_ref(prev); |
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.
Thank you for the suggestions. I fixed it in 4eae3f0
a:pseudo-class { } | ||
body:not(div):noot(span) {} | ||
a:unknown::before { } | ||
a,\nb > .foo:error { } |
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.
a,\nb > .foo:error { } | |
a, | |
b > .foo:error { } |
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.
I fixed it in 3144105 and update snapshots
div :nth-child(2 of .widget) { } | ||
a:hover::before { } | ||
a:-moz-placeholder { } | ||
a,\nb > .foo:hover { } |
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.
a,\nb > .foo:hover { } | |
a, | |
b > .foo:hover { } |
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.
I fixed it in 3144105 and update snapshots
version: "next", | ||
name: "noUnknownPseudoClassSelector", | ||
language: "css", | ||
recommended: false, |
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.
recommended: false, | |
recommended: true, |
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.
I fixed it in 83e8e9f
83e8e9f
to
7db746b
Compare
@togami2864 |
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.
I left one small nit but LGTM
crates/biome_css_analyze/src/lint/nursery/no_unknown_pseudo_class_selector.rs
Outdated
Show resolved
Hide resolved
…ass_selector.rs Co-authored-by: ty <[email protected]>
Summary
close #2625
implement selector-pseudo-class-no-unknown
Test Plan
Add test cases from
stylelint
: https://github.com/stylelint/stylelint/blob/main/lib/rules/selector-pseudo-class-no-unknown/__tests__/index.mjs