Stylelint wont mark errors in VSCode
Asked Answered
F

3

8

VScode doesn't show me any stylint errors.

package.json:

    ...
    "postcss": "^8.4.12",
    "postcss-scss": "^4.0.3",
    "stylelint": "^14.7.1",
    "stylelint-config-sass-guidelines": "^9.0.1",

.stylelintrc.json:

{
    "extends": "stylelint-config-sass-guidelines",
    "files": ["**/*.scss"],
    "customSyntax": "postcss-scss",
    "rules": {
        "color-named": "always-where-possible",
        "max-nesting-depth": 5,
        "selector-max-compound-selectors": 6,
        "selector-no-qualifying-type": [
            true,
            {
                "ignore": ["attribute", "class", "id"]
            }
        ],
        "selector-max-id": 1,
        "no-extra-semicolons": true
    }    
}

vscode settings.json

    ...
    "stylelint.enable": true,
    "css.validate": false,
    "scss.validate": false,
    "less.validate": false,

Thats all i have configured. Im on vscodestylelint 1.2.2. Stylelint it self works in console just fine, vscode just won't show any errors.

Footcandle answered 21/4, 2022 at 14:4 Comment(0)
A
16

Like Stylelint itself, the Stylelint VS Code extension only lints CSS by default. You must configure the extension to lint other languages like SCSS using the stylelint.validate property:

// vscode settings.json
...
"css.validate": false,
"scss.validate": false,
"stylelint.validate": ["css", "scss"],

This will turn off VS Code's built-in validator for CSS and SCSS, and then turn on Stylelint for them.

Ancelin answered 22/4, 2022 at 11:4 Comment(2)
this does not help in my caseMaterially
it helped in my caseBoccioni
M
9

In my case this didn't work because I also had

"stylelint.config": {},

in settings.json, and once I changed it to

"stylelint.config": null,

it started working

Materially answered 22/6, 2022 at 10:35 Comment(1)
Thank you! Removing the line entirely also worked for me. There's a link in the Stylelint extension settings under "Config" named "Edit in settings.json" which appears to create this, which disables linting by default, and overrides settings in .stylelintrcBromeosin
R
1

The fix for me was to include postcss as a value for stylelint to validate, since I'm using postcss. I thought just including the [ "css", "scss" ], values would work since those are the file extensions I'm using but I guess it's the technology being used?

Anyway in VS Code settings add/edit the stylelint.validate option to:

"stylelint.validate": [ "css", "scss", "postcss" ],
Rianon answered 3/3, 2023 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.