[英]How to get stylelint to work in Visual Studio Code?
I am trying to get the stylelint extension to work in visual studio code.我正在尝试让 stylelint 扩展在 Visual Studio 代码中工作。 However, with no success so far.
但是,到目前为止还没有成功。 The extension with a short explanation is here:
带有简短解释的扩展在这里:
https://marketplace.visualstudio.com/items?itemName=shinnn.stylelint https://marketplace.visualstudio.com/items?itemName=shinnn.stylelint
What I did so far: Add到目前为止我做了什么:添加
"stylelint.enable": true,
"css.validate": false,
"scss.validate": false,
to my settings.到我的设置。 But this only deactivates the usual linting without activating stylelint.
但这只会停用通常的 linting,而不会激活 stylelint。 I also read at
我也读过
Stylelint VScode doesn't work Stylelint VScode 不起作用
in a comment that one needs a stylelint.config.js
file.在需要一个
stylelint.config.js
文件的评论中。 However, I don't have one and don't know how to create or put it (in Windows).但是,我没有,也不知道如何创建或放置它(在 Windows 中)。
Edit编辑
I found an "example configuration" file of stylelint:我找到了一个 stylelint 的“示例配置”文件:
https://github.com/stylelint/stylelint/blob/master/docs/user-guide/example-config.md https://github.com/stylelint/stylelint/blob/master/docs/user-guide/example-config.md
So, I guess part of that needs to go into the stylelint.config.js
.所以,我想其中一部分需要进入
stylelint.config.js
。 But which are necessary to get it to work and where do I put it?但是哪些是让它工作所必需的,我应该把它放在哪里?
From the stylelint configuration documentation:从stylelint 配置文档:
The linter expects a configuration object .
linter需要一个配置对象。 You can either craft your own config or extend an existing one.
您可以制作自己的配置或扩展现有配置。
The " Getting started " section of the stylelint website has some suggestions on how to do this eg using the example config, crafting your own config or extending an existing config. stylelint 网站的“入门”部分提供了一些关于如何执行此操作的建议,例如使用示例配置、制作您自己的配置或扩展现有配置。
I believe the quickest way to hit-the-ground-running, so to speak, is to create a configuration object that extends either stylelint-config-standard or stylelint-config-recommended .我相信,可以这么说,最快的方法就是创建一个扩展stylelint-config-standard或stylelint-config-recommended的配置对象。 Use the standard config if you want the linter to enforce stylistic conventions, and use the recommended config if you don't.
如果您希望 linter 强制执行样式约定,请使用标准配置,如果不希望,请使用推荐的配置。
To use the recommended config:要使用推荐的配置:
npm install --save-dev stylelint-config-recommended
.stylelintrc
file that extends the config in the root of your project:.stylelintrc
文件来扩展项目根目录中的配置: { "extends": "stylelint-config-recommended" }
If you are using Yarn 2, you need to do an extra configuration, just run:如果您使用的是 Yarn 2,则需要进行额外的配置,只需运行:
yarn dlx @yarnpkg/pnpify --sdk vscode
https://yarnpkg.com/getting-started/editor-sdks#vscode https://yarnpkg.com/getting-started/editor-sdks#vscode
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.