-
Notifications
You must be signed in to change notification settings - Fork 528
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
no-mergable-selectors should not raise warning with @-blocks or mixins #307
Comments
Hmm, i'm not sure. I feel like the first example is a bad way of writing media queries. The second example is much clearer and easier to follow from a developer experience point of view. Having a block defined once with all contexts contained within is much clearer than duplicating your selectors within a media query context. Technically it is a duplicated selector, it's still targeting the same element but under a certain context. I'm open to discussion here though. I think it's probably another case where we may have become a little too stylistic in our reach.. |
I disagree with this. Where there are many selectors and contexts, I find having single contexts and duplicated selectors easier to grok that the alternative. This is because mostly I tend to care about sets of selectors as related to each other, and I mostly think about understanding an overview of all items within a given context, rather than focusing in on a single element and thinking "what does this selector look like in all contexts". But this discussion isn't about convincing each other on which nesting style is better :) They're both equally valid in my opinion. I think scss-lint is being too heavy handed currently as it is saying "The way you write media queries in native CSS is bad and must be changed". This feels very hostile to people who are comfortable writing CSS but are new to Sass. Forcing people to use Sass features sounds too opinionated for my liking. I do appreciate that "use root level How about this... The notion of "mergable selectors" should take into account the context (i.e. .item {
width: 100%;
@media (min-width: 50em) {
background-color: red;
}
}
@media (min-width: 50em) {
.item {
width: 50%;
}
} should emit a warning stating that the two ".item when the viewport width is >=50em" rules should be merged. In addition to that there can be a new rule, something like In that world, personally I would enable |
Yeah I agree, that's one thing I really want to avoid with sass-lint is it becoming too opinionated. It should be a tool to help everyone enforce their own opinions! 😄 Our whole mindset with sass-lint is for small single purpose rules so it's definitely the right approach to split these ideas up. If you'd like to create a separate issue for the new rule proposal so it doesn't get lost here then that would be appreciated. As for enhancing the |
Had to change my styles because of this. My two cents. I didn't feel my old code was wrong even thought the Old@media all and (min-width: 600px) {
%column {
float: left;
}
}
%column {
padding-right: 1rem;
padding-left: 1rem;
} New%column {
padding-right: 1rem;
padding-left: 1rem;
@media all and (min-width: 600px) {
float: left;
}
} |
in regards to the @include keyframes(fade-in) {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@include keyframes(fade-out) {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
} With the following sort of error: 12:5 warning Rule `0` should be merged with the rule on line 2 no-mergeable-selectors
32:5 warning Rule `100` should be merged with the rule on line 6 no-mergeable-selectors |
Thanks @intellix yeah, I'm currently redoing this rule to take into account all mixins. It will warn you if a selector can be merged within a mixin but wont attempt to warn you across mixins as I think we open up a whole can of worms there, maybe something for the future though. Hoping to have this sorted soon but I've just not had the time in the past few days to work on this. |
@DanPurdy that's awesome that you're taking mixins into account; in addition we also would like to consolidate all styling within a specific media query, so we would also like at least the option to disable the behavior of suggesting merging media queries into other selectors (as @BPScott also describes). Please don't close this issue until that behavior is also implemented, or at least a follow-up issue is created. ;) Thanks for the awesome work! :) |
+1 for this. Just had the same warning for: @keyframes Before {
50% {
transform: rotate(0deg);
}
100% {
transform: rotate(45deg);
}
}
@keyframes After {
50% {
transform: rotate(0deg);
}
100% {
transform: rotate(-45deg);
}
} |
+1 for same use case as @danimalweb |
I am aslo following the approach described by @BPScott and I think that element can be duplicated in different @-blocks. So for now Would be nice to have an option to allow duplication over different @-blocks. |
Hi @eugef I actually meant to label this as a bug after our discussion above. It should be doing what it does but I just haven't had the time recently to get round to fixing it 😢 soon though! |
So I'm handling this with the rule re write for the 1.6 release and the gonzales 3.2.x update. It'll still be look in every node but should be so aggressive with what it tries to merge. I'm sure with feedback we can fine tune it to a level that suits everyone. |
These warnings were annoying me because the noise makes it easy to miss real issues. The `no-mergeable-selectors` rule is one that we do want to have, but right now it asks that you merge selectors in different `@media` blocks. When the next release happens we should put that back. sasstools/sass-lint#307 Similarly, we want `force-element-nesting` but there is a problem with that because there's no easy way to have a nested selector in a list of selectors. sasstools/sass-lint#575 Finally, until they implement per-line overrides, we have to silence `class-name-format` because we don't have control over the ReactModal class names. It's a useful rule to keep class names consistent though. Per-line ignores should be coming soon: sasstools/sass-lint#70
@BPScott @alfaproject @eugef @danimalweb @intellix I've just tested all your examples again with the new mergeable selectors rule I added to 1.6.0 and they all work as discussed! I'll close this issue but if you find anything else then please raise another issue and enjoy 1.6! |
Currently the
no-mergable-selectors
is very aggressive at trying to merge selectors, going so far as to claim that items within@media
and mixins blocks must be moved into each selector. For instance it raises warnings when writing:As it prefers merging those
.item
and.item__inner
selectors, suggesting that you should write it like:In my opinion the first example is just as valid, and is how I prefer to write my scss, as I find logically grouping by viewport size makes more sense. I actually use a mixin for outputting my media queries so replacing the
@media
blocks with@include
s should also not raise warnings.To reproduce this, add the following to the bottom of
no-mergable-selectors.scss
:I would expect this to raise no additional linting errors.
The text was updated successfully, but these errors were encountered: