简体   繁体   English

VS Code 中的 CSS 设置更漂亮

[英]Prettier with CSS settings in VS Code

I have the Prettier extension added to my VS Code editor.我在 VS Code 编辑器中添加了 Prettier 扩展。

When using Less or Sass, the default settings format code like this:使用 Less 或 Sass 时,默认设置格式代码如下:

// Default

.parent_selector {
  .child_selector {
    color: red;
  }
}
// Desired Format

.parent_selector {

  .child_selector {
    color: red;
  }
}

How could I tweak the Prettier CSS settings to achieve this?我如何调整 Prettier CSS 设置来实现这一点? I know it seems trivial, but in bigger code bases it helps readability.我知道这看起来微不足道,但在更大的代码库中,它有助于提高可读性。

As an alternative method;作为替代方法; It can be achieved by using stylelint plugin and stylelint-config-standard rules.可以通过使用stylelint插件和stylelint-config-standard规则来实现。

npm install --save-dev stylelint stylelint-config-standard

After installing them, proceed with ctrl+shift+p on VS Code and run command: stylelint: fix all auto-fixable problems .安装它们后,在 VS Code 上继续ctrl+shift+p并运行命令: stylelint: fix all auto-fixable problems

stylelint:修复所有可自动修复的问题

PS: Consider assigning a keyboard shortcut for stylelint: fix all auto-fixable problems command for easy access. PS:考虑为stylelint: fix all auto-fixable problems分配键盘快捷键stylelint: fix all auto-fixable problems命令,以便于访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM