0

I have bunch of SCSS files. I'd like to find blocks which contains only single property, like:

&__input {
  width: 100%;
}

What tools may be helpful here (for example some NodeJS library etc.) ?

I've created repository to better show what I want to achieve: https://github.com/lusarz/singular-scss-block-finder

lusarz
  • 195
  • 3
  • 10

1 Answers1

0

You'll have to create an Abstract Syntax Tree (AST) for each SCSS file, which will allow you to traverse and analyze your code.

The library scss-parser looks pretty robust for creating ASTs for SCSS, though I have never used it.

austin_ce
  • 1,063
  • 15
  • 28
  • Thank you! I've started with scss-parser but stuck in this place: https://github.com/lusarz/singular-scss-block-finder/blob/141c0f99c09a37453a0e1f88e595c244bd8542bd/lib/utils/SCSSUtils.js#L9 – lusarz Nov 06 '18 at 16:23
  • What part are you stuck with? How to traverse the AST? Also, please accept this answer when you are ready! – austin_ce Nov 06 '18 at 16:28
  • Yes, I don't know how to traverse AST, but it's up to me, I need to learn it :) Thanks for response, unfortunately I cannot accept this answer because my reputation on stackoverflow is too low. – lusarz Nov 06 '18 at 16:37
  • Ok, good luck :) You might not have the reputation to vote up / down, but you should have the ability to "accept" the answer if you click the checkmark underneath the bottom arrow – austin_ce Nov 06 '18 at 16:51