简体   繁体   中英

Atom/Sass-lint: Regex for sass-lint.yml class-name

I have a sass-lint.yml file with the following rule:

class-name-format:
    - 1
    - convention: '^([a-zA-Z]*)(__[a-z]+)?(-[a-z]*)*(--[a-z]+)?$'

The regex can be checked here: https://regex101.com/r/SsVde6/2

Unfortunately I can't get it to work properly.

In the regex tester you see what kind of things I want to include. The first part of the Class name can be PascalCase from then on BEMified ( BEM ) kebabcase (eg: this-is-kebab-case – all lowercase with dashes in between)

A very common pattern would look like: ComponentName__element-name--modifier-name

Quite a few things work already, but I would like to evaluate nested BEM selectors in my scss files as well:

&__burgerCross {…} or &__burger_cross or &__burger__cross for example should be evaluated as false. This would have to be &__burger-cross

But I don't really know how to handle the nested rules.

Any help on sass-lint and regex is very welcome.

The thing I wanted was

I would like to evaluate nested BEM selectors in my scss files as well:

My regex was actually already highlighting all the wanted cases and the not wanted were not matched. The problem was, that the linter cannot lint nested BEM selectors. :(. Read about it here: https://github.com/brigade/scss-lint/issues/339#issuecomment-72404341

So not much we can do here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM