vscode 配置stylelint
时间: 2023-10-07 12:13:40 浏览: 52
要在 VS Code 中配置 Stylelint,您需要按照以下步骤操作:
1. 安装 VS Code 插件:
在 VS Code 中搜索并安装 `stylelint` 插件。
2. 安装 Stylelint:
可以使用 npm 在全局或项目中安装 Stylelint。打开终端并运行以下命令:
```
npm install -g stylelint
```
3. 创建 Stylelint 配置文件:
在项目根目录中创建 `.stylelintrc` 或 `.stylelintrc.json` 文件,并添加您的配置。例如:
```
{
"extends": "stylelint-config-standard",
"rules": {
"indentation": 4,
"color-hex-case": "upper",
"selector-pseudo-element-colon-notation": "single",
"declaration-block-trailing-semicolon": "always",
"block-no-empty": true
}
}
```
4. 配置 VS Code:
在 VS Code 中打开设置(`Ctrl + ,`),并添加以下配置:
```
"stylelint.enable": true,
"stylelint.config": {
"extends": "stylelint-config-standard",
"rules": {
"indentation": 4,
"color-hex-case": "upper",
"selector-pseudo-element-colon-notation": "single",
"declaration-block-trailing-semicolon": "always",
"block-no-empty": true
}
}
```
这将启用 Stylelint 并将其配置为使用您的 `.stylelintrc` 文件中的规则。
5. 检查样式:
在您的 `.css` 或 `.scss` 文件中开始编写样式,并且您应该会在编辑器中看到 Stylelint 的错误和警告。