Skip to content

Fix false positives for single-line comments in selector-type-no-unknown #4049

Closed

Description

@Stanja219

Lots of comments are marked with a
Unexpected unknown type selector "foo" (selector-type-no-unknown)
error

Which rule, if any, is the bug related to?

selector-type-no-unknown

What CSS is needed to reproduce the bug?

.foo1, // this comments is marked as an error
.foo2 {
    color: #fff;
}

What stylelint configuration is needed to reproduce the bug?

{
    "ignoreFiles": "*/vendors/**/*",
    "rules": {
        "block-no-empty": true,
        "block-closing-brace-empty-line-before": "never",
        "block-opening-brace-space-before": "always",

        "color-hex-case": "lower",
        "color-hex-length": "short",
        "color-no-invalid-hex": true,
        "color-named": "never",
        
        "declaration-block-semicolon-newline-after": "always",
        "declaration-block-trailing-semicolon": "always",
        "declaration-colon-space-after": "always",
        "declaration-no-important": true,

        "font-weight-notation": "numeric",

        "function-comma-space-after": "always-single-line",
        "function-comma-space-before": "never",
        "function-whitespace-after": "always",

        "indentation": [4, {
            "except": ["value"]
        }],

        "length-zero-no-unit": true,

        "max-empty-lines": 2,
        "max-nesting-depth": [
            5,{
                "ignore": ["blockless-at-rules"]
            }
        ],

        "media-feature-colon-space-after": "always",
        "media-feature-colon-space-before": "never",
        "media-feature-name-case": "lower",
        "media-feature-parentheses-space-inside": "never",
        "media-feature-range-operator-space-after": "always",
        "media-feature-range-operator-space-before": "always",

        "no-duplicate-selectors": true,
        "no-eol-whitespace": [true, {
            "ignore": ["empty-lines"]
        }],
        "no-missing-end-of-source-newline": true,

        "number-leading-zero": "always",

        "property-no-unknown": true,
        "property-case": "lower",

        "rule-empty-line-before": [ "always", {
            "except": ["first-nested"],
            "ignore": ["after-comment"]
        } ],

        "selector-attribute-brackets-space-inside": "never",
        "selector-attribute-operator-space-after": "never",
        "selector-attribute-operator-space-before": "never",
        "selector-attribute-quotes": "always",
        "selector-combinator-space-after": "always",
        "selector-combinator-space-before": "always",
        "selector-list-comma-newline-after": "always",

        "selector-pseudo-class-case": "lower",
        "selector-pseudo-class-parentheses-space-inside": "never",
        "selector-pseudo-element-colon-notation": "double",
        "selector-type-case": "lower",

        "selector-max-id": 0,
        "selector-pseudo-class-no-unknown": true,
        "selector-type-no-unknown": true,

        "string-quotes": "double",

        "unit-case": "lower",
        "unit-no-unknown": true,

        "value-keyword-case": "lower",

        "value-list-comma-space-after": "always-single-line",
        "value-list-comma-space-before": "never"
    }
}

Which version of stylelint are you using?

9.9.0

How are you running stylelint: CLI, PostCSS plugin, Node.js API?

gulp-stylelint with stylelint-report.txt
and VSCode

Does the bug relate to non-standard syntax (e.g. SCSS, Less etc.)?

less

What did you expect to happen?

"No warnings to be flagged."

What actually happened (e.g. what warnings or errors did you get)?

Unexpected unknown type selector "this" (selector-type-no-unknown)
Unexpected unknown type selector "comments" (selector-type-no-unknown)
Unexpected unknown type selector "is" (selector-type-no-unknown)
Unexpected unknown type selector "marked" (selector-type-no-unknown)
Unexpected unknown type selector "as" (selector-type-no-unknown)
Unexpected unknown type selector "an" (selector-type-no-unknown)
Unexpected unknown type selector "error" (selector-type-no-unknown)

Activity

  1. hudochenkov commented on Apr 25, 2019

    @hudochenkov
    Member

    Thanks for the report and for using the template.

    I can reproduce this issue in demo when syntax is set to Less. When I set it to SCSS there is no issue. In rule code I don't see anything SCSS specific.

    Looks like there is another issue with a comment inside selector in Less #3975. My guess it's postcss-less having hard time parse selector with a comment inside it.

  2. ntwb commented on Apr 26, 2019

    @ntwb
    Member

    Maybe we can enhance our existing tests here so that any future postcss-less release we'll be ready for in this regard?

  3. hudochenkov commented on Apr 26, 2019

    @hudochenkov
    Member

    If we just add these examples to tests, then our tests will fails all the time.

  4. ha404 commented on Aug 28, 2019

    @ha404

    The same thing happens to styled-components in JS.

  5. jeddy3 commented on Jan 17, 2022

    @jeddy3
    Member

    Closing as related to custom syntaxes.

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