【问题标题】:EditorConfig for VS Code not workingVS Code 的 EditorConfig 不起作用
【发布时间】:2018-04-01 10:47:41
【问题描述】:

我使用 VS Code 作为编辑器。我们有一个.editorconfig 文件,其中包含格式配置。我们都在我们的编辑器中使用扩展名 EditorConfig 来格式化我们的 HTML 和 CSS 通用格式。我已经从这里安装了 VS Code 的扩展 EditorConfig:https://github.com/editorconfig/editorconfig-vscode

我们的 .editorconfig 文件如下所示:

# This is the top-most .editorconfig file (do not search in parent directories)
root = true

### All files
[*]
# Force charset utf-8
charset = utf-8
# Indentation
indent_style = tab
indent_size = 4
# line breaks and whitespace
insert_final_newline = true
trim_trailing_whitespace = true
# end_of_line = lf

### Frontend files
[*.{css,scss,less,js,json,ts,sass,php,html,hbs,mustache,phtml,html.twig}]

### Markdown
[*.md]
indent_style = space
indent_size = 4
trim_trailing_whitespace = false

### YAML
[*.yml]
indent_style = space
indent_size = 2

### Specific files
[{package,bower}.json]
indent_style = space
indent_size = 2

我找不到任何键盘快捷键、设置或其他。如何让我的扩展程序从 .editorconfig 文件中执行操作?

【问题讨论】:

    标签: html css visual-studio-code editorconfig


    【解决方案1】:

    我自己的解决方案:

    我遇到的问题是,我在vscode 中添加了扩展名editorconfig,但没有为它安装npm package。因此,仅将扩展添加到您的 vscode 是不够的,您还必须安装包,以便它可以运行。

    我像这样安装了npm package 全局:npm install -g editorconfig

    之后我添加了扩展并启用了它。现在它完美运行了。

    这里是所需 npm 包的链接:https://www.npmjs.com/package/editorconfig

    这里是您的 vscode 所需扩展的链接:https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig

    【讨论】:

    • 这个解决方案也适用于我。扩展程序没有检查并警告您,这太疯狂了!
    • @johey 至少,我希望在vscode 扩展的描述中找到这些信息......我只是自己想通了,运气好:)
    • 它仍然对我不起作用。我安装了 node、editorconfig 包和 vscode 扩展。有什么遗漏吗?可能在 vscode 设置中?
    • @Nachokhan 确保您没有“竞争”插件来处理样式并覆盖您的 editorconfig 设置。
    【解决方案2】:

    除了以上所有我还需要打开编辑器格式保存选项。

    {
       "editor.formatOnSave": true
    }
    

    【讨论】:

      【解决方案3】:

      我收到错误“Extension EditorConfig cannot format ...”(在 IDE 底部,几秒钟后消失)。

      更改首选项(ctrl+,,搜索format 并将Editor:DefaultFormatter 设置为None(而不是EditorConfig))为我解决了这个问题(是的,很有趣,这确实启用了.editorconfig 的用法 - 不是任何其他格式规则)

      Codium:1.60.2,带有 EditorConfig:v0.16.6

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-08
        • 2018-02-04
        • 2017-12-18
        • 1970-01-01
        • 2020-06-14
        • 2022-01-13
        • 2020-04-13
        • 1970-01-01
        相关资源
        最近更新 更多