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

False positive for non standard selectors in no-duplicate-selectors #2199

Closed
cookch10 opened this issue Dec 16, 2016 · 6 comments
Closed

False positive for non standard selectors in no-duplicate-selectors #2199

cookch10 opened this issue Dec 16, 2016 · 6 comments
Labels
status: ready to implement is ready to be worked on by someone syntax: scss relates to SCSS and SCSS-like syntax type: bug a problem with a feature or rule

Comments

@cookch10
Copy link

When using stylelint v7.6.0 as follows:

package.json (simplified):

{
  "scripts": {
    "lint:styles": "stylelint --syntax scss \"src/**/*.scss\""
  }
}

My .stylelintrc config (uses stylelint-config-standard v11.0.0):

{
  "extends": "stylelint-config-standard",
  "rules": {
    "function-url-quotes": "none",
    "selector-pseudo-element-colon-notation": "single"
  }
}

given the following Sass (scss file): Sassmeister gist

.widget-container {
  $variation-without-image: #{"&[data-variation^=without_image]"};
  $has-buttons: #{"&[data-has-buttons]"};

  #{$variation-without-image} {
    & {
      #{$has-buttons} {
        .grid.widget__grid {
          border: 1px solid red;
        }
      }
    }

    .grid.widget__grid {
      border: 1px solid orange;
    }
  }
}
npm run lint:styles

The following results in an error:

:5  ×  Unexpected duplicate selector ".widget-container #{$variation-without-image}"   no-duplicate-selectors

There is no duplicate selector here. If I change the Sass to the following (which yields the same output): given the following Sass (scss file), there is no error observed: Sassmeister gist

.widget-container {
  $variation-without-image: #{"&[data-variation^=without_image]"};
  $has-buttons: #{"&[data-has-buttons]"};

  #{$variation-without-image} {
    #{"#{$has-buttons}"} {
      .grid.widget__grid {
        border: 1px solid red;
      }
    }

    .grid.widget__grid {
      border: 1px solid orange;
    }
  }
}
@jeddy3 jeddy3 added syntax: scss relates to SCSS and SCSS-like syntax status: needs investigation triage needs further investigation labels Dec 17, 2016
@jeddy3
Copy link
Member

jeddy3 commented Dec 17, 2016

:5 × Unexpected duplicate selector ".widget-container #{$variation-without-image}" no-duplicate-selectors

I think we should ignore any resolved non-standard selectors in this rule i.e. those with interpolation.

If there are no objections to this, I'll point @cookch10 in the direction of how to do this.

@jeddy3 jeddy3 added status: needs discussion triage needs further discussion and removed status: needs investigation triage needs further investigation labels Dec 17, 2016
@cookch10
Copy link
Author

cookch10 commented Jan 3, 2017

@jeddy3 , what are your thoughts on this one? Is this a valid bug?

@jeddy3
Copy link
Member

jeddy3 commented Jan 3, 2017

Whoops, I didn't notice those thumbs up.

@cookch10 Yes, this is a bug. Non-standard constructs should be ignored. Would you like to contribute a fix? It will involve checking that each resolved selector is of standard syntax. FYI, tests are run as so.

@jeddy3 jeddy3 added status: ready to implement is ready to be worked on by someone type: bug a problem with a feature or rule and removed status: needs discussion triage needs further discussion labels Jan 3, 2017
@jeddy3 jeddy3 changed the title Unexpected duplicate selector error observed when no duplicate selector is present False positive for non standard selectors in no-duplicate-selectors Jan 3, 2017
@cookch10
Copy link
Author

cookch10 commented Jan 5, 2017

@jeddy3, I would be interested in contributing a fix for this. I'll need a little time to get familiar with the project, so no promises on it being a quick turnaround :)

@jeddy3
Copy link
Member

jeddy3 commented Jan 5, 2017

I would be interested in contributing a fix for this.

Awesome! Take your time, there's no rush on these things :)

@hudochenkov
Copy link
Member

This issue is similar to #2198. The rule works as expected. Explanation why in #2198 (comment).

TL;DR: A rule with a parent selector & has the same selector as its ancestor. That is why the rule shows a warning.

.widget-container {
  $variation-without-image: #{"&[data-variation^=without_image]"};

  #{$variation-without-image} { // ← .widget-container #{$variation-without-image}
    & { // ← .widget-container #{$variation-without-image}
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready to implement is ready to be worked on by someone syntax: scss relates to SCSS and SCSS-like syntax type: bug a problem with a feature or rule
Development

No branches or pull requests

3 participants