Skip to content

[scss] linter update for variables in #{} #75905

Closed

Description

@nagman
  • VSCode Version: 1.35.1
  • OS Version: Ubuntu 18.04

In this piece of SCSS code:

@for $i from 0 to 9 {
  .enterActive &:nth-child(#{$i}) {
    transition-delay: $i * 30ms;
  }
}

the #{$i} is parsed as an id (whether it's not), so the linter throws me that I shouldn't be using id selectors:

Selectors should not contain IDs because these rules are too tightly coupled with the HTML

image

Activity

  1. added
    css-less-scss
    feature-request
    on Jun 24, 2019
  2. added this to the Backlog milestone on Jun 24, 2019
  3. changed the title [-]SCSS Linter update for variables in #{}[/-] [+][scss] linter update for variables in #{}[/+] on Jul 25, 2019
  4. octref commented on Oct 22, 2019

    @octref
    Contributor

    Seems already fixed.

  5. added
    verification-needed
    on Oct 22, 2019
  6. OldStarchy commented on Oct 23, 2019

    @OldStarchy

    Running the latest build of insiders and this is definitely still happening

    Version: 1.40.0-insider (user setup)
    Commit: c58aaab
    Date: 2019-10-22T05:27:32.053Z
    Electron: 6.0.12
    Chrome: 76.0.3809.146
    Node.js: 12.4.0
    V8: 7.6.303.31-electron.0
    OS: Windows_NT x64 10.0.18362

    image

  7. octref commented on Oct 23, 2019

    @octref
    Contributor

    @aNickzz I can't repro from the original piece. Please open a new issue with reproducible steps.

  8. roblourens commented on Oct 29, 2019

    @roblourens
    Member

    I also see this, I suggest that we reopen this and close the new issue to keep the history

  9. 5 remaining items

  10. OldStarchy commented on Mar 3, 2020

    @OldStarchy

    Are you sure this should be labelled with feature-request instead of a bug? Maybe it would get a bit more attention with the correct label.

  11. added
    bug
    and removed
    feature-request
    on Mar 3, 2020
  12. removed their assignment
    on May 1, 2020
  13. aeschli commented on Nov 11, 2020

    @aeschli
    Contributor

    It's a bug in the parser.

  14. OldStarchy commented on Nov 25, 2020

    @OldStarchy

    So, the linting rule checks for a # at the beginning of a SimpleSelector node. , this is a false positive because in this case the first (and only) descendent of the first identifier in the SimpleSelector is an Interpolation.

    I would think that the linter could check for this and not add the Marker if the # is coming from an Interpolation. This is what I've done on my fork and have had success running some new tests to check this.

    As I'm not sure that the structure of the node tree will always be consistent with what I saw, so I did this by checking for an Interpolation at the first child of each node down the tree, rather than assuming that if an Interpolation node exists, it would always be the nth grandchild of the SimpleSelector.

    image

    However, if you're saying that this is rather a problem with the parser, rather than the linter, then I'm not really sure how to tackle this. I'd like to make a PR for this so please let me know what strategy you'd like to take for this.


    Also, while looking through this I discovered that the SimpleSelector is checked as a whole as an ID selector, that is to say, only the first component of the SimpleSelector is checked for ID's

    #id {} // This will raise a warning about an id selector
    div#id {} // This will not raise a warning, as the id selector isn't at the front

    Though that should be in its own issue I guess.

  15. aeschli commented on Nov 25, 2020

    @aeschli
    Contributor

    Thanks @aNickzz for looking at this. Yes, I think you got this right, the linter check for # is too simple.
    Instead of looking for a interpolation, what about looking for a IdentifierSelector node inside the SimpleSelector?

    That would then fix the second point (no warning on div#id {}) as well.

  16. added
    verified
    on Jan 27, 2021
  17. locked and limited conversation to collaborators on Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugcss-less-scssverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions