Skip to content

**:not()** with a selector list doesn't expand & symbol #4313

Closed

Description

@WORMSS

:not(&--a):not(&--b) does expand the & symbol into the parent's selector as expected.
:not(&--a, &--b) doesn't expand the & symbol into the parent's selector.

To reproduce:

.works {
  &:not(&--a):not(&--b):hover {
    background-color: green;
  }
}

.broken {
  &:not(&--a, &--b):hover {
    background-color: green;
  }
}

Current behavior:

.works:not(.works--a):not(.works--b):hover {
  background-color: green;
}

.broken:not(&--a, &--b):hover {
  background-color: green;
}

Expected behavior:

.works:not(.works--a):not(.works--b):hover {
  background-color: green;
}

.broken:not(.broken--a, .broken--b):hover {
  background-color: green;
}

Environment information:

  • less version: 4.2.2
  • nodejs version: any
  • operating system: any

We are currently in the middle of a battle of linters. We are told :not(a):not(b) is being classed as complex, and should be changed to :not(a, b)but it appears less forgets to expand when this feature is being used.4.2.2at least compiles the syntax (though incorrectly) our older version4.1.3` just keels over completely.. So I am guessing this is a relatively new feature and hasn't had much usage yet.

Activity

  1. dosubot commented on Jan 30, 2025

    @dosubot

    The issue you're encountering with the & symbol not expanding within a selector list inside :not() is a known limitation in Less. In version 4.2.2, there was a fix related to nested pseudo-selector parsing, which might have improved some aspects of handling :not(), but it seems that the specific case of selector lists within :not() still doesn't expand the & symbol as expected [1].

    This behavior indicates that Less currently does not support expanding the & symbol within a selector list inside :not(). The workaround would be to avoid using selector lists in :not() when you need the & symbol to expand, and instead use separate :not() pseudo-classes as you did in the .works example.

    If this is causing issues with linters, you might need to adjust the linter rules or continue using the workaround until a future update potentially addresses this limitation.

    To continue talking to Dosu, mention @dosu.


    Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

  2. WORMSS commented on Jan 30, 2025

    @WORMSS
    Author

    I am guessing @puckowski would be the best person for this type of issue? Due to his work on the latest fix for listed selectors?

  3. puckowski commented on Jan 30, 2025

    @puckowski
    Contributor

    Thank you for the issue report. I'll spend some time this weekend on this issue and I will try to come up with a fix PR.

  4. puckowski commented on Jan 31, 2025

    @puckowski
    Contributor

    I think I have a fix. Will work on adding more tests and try to get a PR submitted this weekend.

  5. added 4 commits that reference this issue on Jan 31, 2025
  6. puckowski commented on Feb 1, 2025

    @puckowski
    Contributor

    PR #4314 should resolve this issue, but it looks like we may be having new CI problems.

  7. puckowski commented on Feb 1, 2025

    @puckowski
    Contributor

    FYI figured out the new CI issue so PR #4314 can be merged after review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions