-
-
Notifications
You must be signed in to change notification settings - Fork 475
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 noDuplicateAtImportRules #2658
feat(biome_css_analyzer): implement noDuplicateAtImportRules #2658
Conversation
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! It would be better to add test cases ported from the stylelint repo. https://github.com/stylelint/stylelint/blob/main/lib/rules/no-duplicate-at-import-rules/__tests__/index.mjs
pub NoDuplicateAtImportRules { | ||
version: "next", | ||
name: "noDuplicateAtImportRules", | ||
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, |
|
||
fn run(ctx: &RuleContext<Self>) -> Option<Self::State> { | ||
let node = ctx.query(); | ||
// let mut import_url_list = HashSet::new(); |
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.
This should be removed
"Duplicate @import rule." | ||
}, | ||
) | ||
.note(markup! { | ||
"Looks like you imported the same file twice. Consider removing one to get rid of this 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.
We should follow rule pillars for diagnostics.
https://biomejs.dev/linter/#rule-pillars
AnyCssAtRule::CssImportAtRule(import_rule) => { | ||
let import_url = import_rule.url().ok()?.text().to_lowercase(); | ||
if let Some(media_query_set) = import_url_map.get_mut(&import_url) { | ||
// if the current import_rule has no media queries or there are no queries safed in the |
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.
// if the current import_rule has no media queries or there are no queries safed in the | |
// if the current import_rule has no media queries or there are no queries saved in the |
@togami2864 Thanks for the review! |
@DerTimonius You can use |
CodSpeed Performance ReportMerging #2658 will not alter performanceComparing Summary
|
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 small nits. Could you fix and update snapshots?
}, | ||
) | ||
.note(markup! { | ||
"To fix this issue, remove one of the duplicated imports." |
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 fix this issue, remove one of the duplicated imports." | |
"Consider removing one of the duplicated imports." |
rule_category!(), | ||
span, | ||
markup! { | ||
"Duplicate @import rule." |
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.
"Duplicate @import rule." | |
"Each "<Emphasis>"@import"</Emphasis>" should be unique unless differing by media queries." |
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!
Summary
This PR implements the
noDuplicateAtImportRules
(stylelint-rule) to the css-analyzer.It would show an error with the following examples:
The following code would be valid:
This also includes a check for imported media queries, so the following code would be valid:
This one was the biggest issue for me, I came up with a combination of HashMap and HashSet to check duplicates, there's probably an easier solution I overlooked.
Test Plan
I suppose the test cases in the valid/invalid files are enough?
Closes #2627