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): noDuplicateCustomProperties
#2783
base: main
Are you sure you want to change the base?
feat(biome_css_analyzer): noDuplicateCustomProperties
#2783
Conversation
CodSpeed Performance ReportMerging #2783 will not alter performanceComparing Summary
|
8cb3658
to
eebb582
Compare
let mut custom_properties: Vec<SyntaxToken<CssLanguage>> = vec![]; | ||
for item in node { | ||
if let Some(css_declaration) = item.as_css_declaration_with_semicolon() { | ||
if let Ok(property) = css_declaration.declaration().ok()?.property() { | ||
if let Some(property) = property.as_css_generic_property() { | ||
if let Some(ident) = property.name().ok()?.as_css_identifier() { | ||
let value_token = ident.value_token().ok()?; | ||
custom_properties.push(value_token); | ||
} | ||
} | ||
} | ||
} | ||
} |
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.
Opinion: I think you can get rid of the mut
here by using a filter_map
and it will return an Iterator
that you can possible use directly with check_duplicate_custom_properties
.
let mut custom_properties: Vec<SyntaxToken<CssLanguage>> = vec![]; | |
for item in node { | |
if let Some(css_declaration) = item.as_css_declaration_with_semicolon() { | |
if let Ok(property) = css_declaration.declaration().ok()?.property() { | |
if let Some(property) = property.as_css_generic_property() { | |
if let Some(ident) = property.name().ok()?.as_css_identifier() { | |
let value_token = ident.value_token().ok()?; | |
custom_properties.push(value_token); | |
} | |
} | |
} | |
} | |
} | |
let custom_properties = node.into_iter().filter_map(|item| { | |
item.as_css_declaration_with_semicolon() | |
.and_then(|css_declaration| { | |
css_declaration | |
.declaration() | |
.ok()? | |
.property() | |
.ok()? | |
.as_css_generic_property() | |
.and_then(|css_generic_property| { | |
css_generic_property | |
.name() | |
.ok()? | |
.as_css_identifier() | |
.and_then(|css_identifier| css_identifier.value_token().ok()) | |
}) | |
}) | |
}); |
You don't need to use it like above, as long as you are returning an Option
(Some
/None
) it should be okay!
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.
@abidjappie
I appreciate so much for your feedback!! That's clean and readable.
I wonder if we should start writing a semantic model. I think this rule would benefit from it |
@ematipico |
Sure, I suggest talking with @togami2864, I know he has plans about it |
Summary
Fixes #2784
Test Plan