eslint-plugin-css-modules icon indicating copy to clipboard operation
eslint-plugin-css-modules copied to clipboard

no-undef-class with :global

Open eddiemoore opened this issue 7 years ago • 3 comments

If you have a global class that you only want something applied when it is a child of another class.

/* fails */
.holder :global .Select {}

If .holder doesn't have a class of it's own, it says that .holder is unused. To get it to pass we need to change .holder to have css applied otherwise it has an error of no-undef-class with .holder

/* passes */
.holder { display: block; }
.holder :global .Select {}

eddiemoore avatar Mar 21 '17 08:03 eddiemoore

It is happening because i am removing all the selectors with pseudoclass :global.

To get around this problem just use it like this:

.holder {
  :global .Select {}
}

atfzl avatar Mar 21 '17 09:03 atfzl

Your fix cannot solve the following case:

:global(.Select) {
  .holder {}
}

However, there is workaround:

.holder {}
:global(.Select) {
  .holder {}
}

mnowotnik avatar Nov 23 '17 15:11 mnowotnik

Is there any updates on this? The only workaround that worked for my use case was to define empty classes for all of the classes that have a :global selector as a child. The nested suggestion does not work with vanilla CSS.

jch254 avatar Aug 16 '19 01:08 jch254