Skip to content

implicit-nesting-selector

Reports a custom variant selector without &, which matches descendants.

This rule reports a @custom-variant selector without &. Without &, the selector matches descendants of the element, not the element itself. In the example, hocus: would match hovered elements inside the element.

Reported

@custom-variant hocus (:hover);implicit-nesting-selector: variant selector `:hover` is relative to `&` and means `& :hover`; write the `&`, or add `scope(document)` to the definition to select a document-level element

Fixed

@custom-variant hocus (&:hover);

How to fix

  • Add & where the element belongs in the selector, as in the example.
  • If the variant should match descendants, write that explicitly, such as (& :hover).

Rule settings

PresetSeverity
recommendedwarn
strictdeny
stylisticoff

Configure lint to change the severity or options.