Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add no-duplicate-at-import-rules first draft #2963
changed the title from
add no-duplicate-at-import-rules first draft
[WIP] add no-duplicate-at-import-rules first draft
Oct 14, 2017
@agatac This is a very good start, thanks!
Similar to how the
font-family-no-duplicate-names rule works, I believe this rule should know that
@import url("a.css") and
@import url('a.css') are all duplicates.
Can you adapt the rule (and add tests) for this please? Having a look at how
postcss-value-parser to parse
@import statements might be useful here e.g. to parse out the following:
- the filename to import, so you check for dupes regardless of the format e.g.
"a.css", "url(a.css)" etc.
- the media query list (if there is one), so you can check that imports with the same filename also have the same media query list.
@agatac Thanks for making the changes. I believe the rule will be even more useful now.
The implementation (and tests) so far have just made me realise we can (although, I'm not sure if we should) take the media query list parsing further e.g. the following are technically duplicates:
@import "a.css" tv, projection; @import "a.css" projection, tv;
@agatac & @stylelint/core I believe making use of postcss-media-query-parser will enable the extraction (and correct comparison) of the various media features within the media query list. The question is, is it worth the effort to implement it (at this stage) for an arguably seldom used aspect of
I also added the following test (rejected):
If I'm correct this should be rejected. The first import is a subset of the second one, therefore it's a duplicate. Let me know what you think.
Oh wow, you've already made use of the media query parser. That's fantastic to see!
If I'm correct this should be rejected.
Yes, I believe that's correct.
I guess the last step is to account/test for non-boolean media features, e.g. I believe the following are duplicates:
@import "a.css" tv, (min-width : 500px); @import url(a.css) ( min-width:500px ), tv;
Do you think detecting these duplicates is achievable?
@agatac Thanks for your continued amends.
I was just thinking the same myself. Seems like a simple and eloquent solution.
Yes, I believe so.
@stylelint/core If someone has a spare moment, can you cast your eyes over this PR please? This rule will be added to
I don't have time to look in depth right now, but it looks to me like the mediaQueries is a flat array contain all mediaQueries that have been encountered? (I could be totally wrong about this - late night last night). So it seems like if you had:
@import "a.css" screen @import "b.css" tv @import "a.css" tv
it would fail inappropriately because both conditions for a duplicate have been met? I need to checkout the repo and play with it to see if that's the case, but in the mean time it wouldn't hurt to add something like that as a test?
It's a rule for ensuring quality. At least two reviewers (except small docs PRs). All reviewers should approve PR. CI should be green. Only then PR could be merged.