eslint-plugin-css-modules
eslint-plugin-css-modules copied to clipboard
False negative with :not
SCSS:
.root {
&:not(.selected) {
opacity: 0.5;
}
}
JS:
<div className={cx(styles.root, styles.selected)} />
Result:
Class 'selected' not found (css-modules/no-undef-class)
This is not a bug. In the example above, there're no selectors that target .selected in the SCSS file. :not(.selected) targets anything other then .selected so the error is semantically correct - .selected is undefined.
You should be able to avoid this error by using string literals for classes that aren't defined in the CSS module:
<div className={cx(styles.root, 'selected')} />
*syntax unchecked