为什么 stylelint vscode 扩展不能在我的电脑上运行?

Why the stylelint vscode extension is not working on my computer?

我按照guide安装了stylelintvscode扩展,但是它在我的电脑上不起作用。

我很确定我已经完成了所有必要的步骤。

但是扩展还是没有自动验证css,是怎么回事?

再次阅读guide后,我找到了设置stylelint.config并理解了它的定义:

Set stylelint config option. Note that when this option is enabled, stylelint doesn't load configuration files.

所以我查看了我的 vscode 用户设置,哦,stylelint.config: {}。将其更改为 null 后,stylelint 会立即自动验证 css 文件。

呼~

我买了一台新电脑并安装了最新版本 1.2.1,但没有任何效果 - 然后我检查了旧电脑上的版本,它的版本是 0.86.0。将版本更改为旧版本并重新加载 VSC 时,它立即起作用。

我遇到了同样的问题。让我分享一下我是如何让它与 Stylelint extension ver.1.2.2:

一起顺利工作的

在根项目文件夹中,您应该具有以下结构:

/path/to/project/
                .vscode/
                       settings.json
                       extensions.json
                src/
                .stylelintrc.json
                package.json

extensions.json

From the official documentation: Starting with 1.x, vscode-stylelint will depend on having a copy of Stylelint installed in the open workspace (recommended) or globally (not recommended). If the extension doesn't seem to be linting any documents, make sure you have Stylelint installed

{
  "recommendations": ["stylelint.vscode-stylelint"]
}

settings.json

{
  "css.validate": false,
  "less.validate": false,
  "scss.validate": false,
  "stylelint.validate": ["css", "scss"]
}

package.json

Some of the following packages are to detect reserved words inside sass files such us @use, @export, @global and so on. I think you don't actually need all of them, but it is my configuration.

    // DevDependencies
    "stylelint": "^14.6.0",
    "stylelint-config-css-modules": "^4.1.0",
    "stylelint-config-standard-scss": "^3.0.0",
    "stylelint-scss": "^4.2.0"

.stylelintrc.json

{
  "extends": ["stylelint-config-standard-scss", "stylelint-config-css-modules"],
  "plugins": ["stylelint-scss"],
  "rules": {
    "at-rule-no-unknown": null,
    "scss/at-rule-no-unknown": true
  }
}

配置好每个文件后,记得关闭vscode再打开,才能开始享受Stylelint!