Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false positives for universal selector in no-descending-specificity #3738

Open
yukipastelcat opened this issue Oct 22, 2018 · 2 comments
Labels
good first issue is good for newcomers status: ask to implement ask before implementing as may no longer be relevant type: bug a problem with a feature or rule

Comments

@yukipastelcat
Copy link

.something {
  & > * {
    &:not(:first-child) {
      margin-right: 16px;
    }
    &:not(:last-child) {
      margin-left: 16px;
    }
  }
  &-element {
    & > * { /*Expected selector ".something-element > *" to come before selector ".something > *:not(:first-child)" (no-descending-specificity) */
      &:not(:first-child) {
        margin-top: 16px;
      }
      &:not(:last-child) {
        margin-bottom: 16px;
      }
    }
  }
}

My stylelint.config.js:

module.exports = {
  extends: ['stylelint-config-recommended-scss'],
};
@jeddy3 jeddy3 changed the title Why am I getting no-descending-specificity error? Fix false positives for universal selector in no-descending-specificity Oct 22, 2018
@jeddy3
Copy link
Member

jeddy3 commented Oct 22, 2018

@yukipastelcat Thanks for the report.

Why am I getting no-descending-specificity error?

Technically .something-element > * has a specificity of 0,1,0 and .something > *:not(:first-child) has a higher specificity of 0,2,0, yet .something-element > * appears after .something > *:not(:first-child) in the source order. The rule is comparing them because I believe the last compound selector in each selector match i.e. it's the universal selector. I can see how this could be undesirable because:

a. & > * { } has no declarations
b. the universal selector is a odd thing to match

I believe this might be duplicate of #2489. It's proving a difficult problem to crack and this is proving to be a problematic rule, so please help in that issue if it's related or here if you think it's a separate one.

@jeddy3 jeddy3 added status: ready to implement is ready to be worked on by someone type: bug a problem with a feature or rule good first issue is good for newcomers labels Oct 22, 2018
czr added a commit to czr/dashboard that referenced this issue May 10, 2019
This rule behaves highly counter-intuitively with rules like:

    .foo > *:first-child { ... }
    .bar > *

It's only looking at the universal selector and not paying attention
to the context.

See stylelint/stylelint#3738
Copy link
Contributor

This issue is older than one month. Please ask before opening a pull request, as it may no longer be relevant.

@github-actions github-actions bot added status: ask to implement ask before implementing as may no longer be relevant and removed status: ready to implement is ready to be worked on by someone labels Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue is good for newcomers status: ask to implement ask before implementing as may no longer be relevant type: bug a problem with a feature or rule
Development

No branches or pull requests

3 participants