question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sass/Scss nested rules not sorted by leftovers selector

See original GitHub issue

Hello,

The problem

I found no way to configure position of nested rules when working with scss syntax (not tested on less/sass). I thought that nested rules would be catched by the leftovers selector ("...") but that’s not the case : every nested rules always gets at the end

current behavior

with this config :

"sort-order": [
	[ "color", "font-weight" ],
	[ "..." ],
	[ "$include" ]
]

and this main.scss

.container {
    & > p {
        font-weight: bold;
    }
    @include mediaDestkop {
        color: blue;
    }
    color: red;
}

We get this result (note that & > p is at the end) :

.container {
    color: red;
    @include mediaDestkop {
        color: blue;
    }
    & > p {
        font-weight: bold;
    }
}

Expected :

I would expect that nested rules get catched by the leftovers selector and sorted accordingly :

.container {
    color: red;
    & > p {
        font-weight: bold;
    }
    @include mediaDestkop {
        color: blue;
    }
}

Alternative

Another option could be to add a new identifier to support nested rules in the same way $include, $extend, etc. does. A deleted user mentioned in https://github.com/csscomb/csscomb.js/issues/462#issuecomment-246597260 to add a new "$selector" keyword (not sure the term is ideal, but the idea is interesting).

Help ?

I would be glad to help but after looking at the code at https://github.com/csscomb/csscomb.js/blob/dev/src/options/sort-order.js I could not find where nested declarations are treated. @tonyganch if you could point me to a direction, I could try to do a PR. 😃

NB: I created this issue event if there is a discussion that started in #462 comments, since the original issue isn’t exactly the same.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jdaltoncommented, Apr 30, 2019

Hi @tfritsch-km!

After forking the repo, cloning the repo, and npm i’ing you can explore the package.json for the various scripts to run (e.g. npm run build and npm test). Start with modifying sort-order option. Possibly the _sortLeftovers method. Then adding a test to test/options/sort-order/process/test.js. The files used in the tests come from the fixture folders of css, less, sass, and scss.

0reactions
jdaltoncommented, May 1, 2019

Awesome! Please open a PR and we can work through the issues together 🤝

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sass / Scss: Changing the order of nested psuedo selectors for
What I am attempting to do is generate div.test:hover:before (the current output is before:hover). NOTE: I am able to generate the expected CSS...
Read more >
Style Rules - Sass
Each complex selector (the ones between the commas) is nested separately, and then they're combined back into a selector list. SCSS; Sass; CSS....
Read more >
Nesting in Sass
As seen in the nested Sass above, we can organize all styles relating to a specific area of the layout (like nav ,...
Read more >
Organizing Nested Selectors in Sass - Viget
I love trying to figure out the best organizational systems for my code. At Viget, FEDs and Devs do regular code reviews and...
Read more >
Leftovers and Food Safety
To ensure that leftovers are safe to eat, make sure the food is cooked to a safe temperature and refrigerate the leftovers promptly....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found