UPDATE: I've come to the conclusion that RegExp is not a viable option for this particular problem.
Thanks for your help.
The problem
TLDR: I want to create a RegExp that can scan all nested SCSS selectors, and match everything that is not kebab-case (with the exception of pseudo selectors
first-child
,last-child
, etc).
I am looking for a RegExp to use in combination with the selected-nested-patterns
from stylelint
.
I want to forbid any kebab case nested selectors in our SCSS Modules.
Unfortunately I could not manage to get a negative lookahead working.
Requirements:
- everything that is
(&:>+~*\w)+
- not followed by one or more hyphens
(?!-)+
- not followed by one or more underscore
(?!_)+
- followed by 0 or more white space or character
(?:([\w\s])*)
- accept CSS pseudo selectors in kebab case (
first-child
,last-child
)
class // YES
class-class // NO
class--class // NO
somethingSomething // YES
&Class // YES
&-class // NO
&--class // NO
&.class // YES
&__class // NO
input > input // YES
& > & // YES
~ class // YES
> div // YES
a, c // YES
&.disabled:disabled:hover // YES
& > div:first-child // YES
&:last-child // YES