Search code examples
node.jsparsingsassabstract-syntax-treescss-lint

How to find CSS/SCSS classes that contains single property


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


Solution

  • 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.