Intellij 错误地格式化了我的 `.yml` 文件,我在样式设置中看不到任何错误。我该如何修复它?

问题描述 投票:0回答:2

Intellij 不断错误地格式化我的

spotbugs.yml
文件,因此破坏了 github 操作。
我不明白为什么要这样做:

上周工作正常,我没有对格式化配置进行任何更改,但现在,每次我从文件中更改焦点时,Intellij 都会像这样自动格式化,然后保存它。我该如何解决它?

我不明白的是它的格式似乎无效

yaml
,对吗?

intellij-idea yaml
2个回答
1
投票

YAML 的语法使其与非 2 个空格的缩进不兼容。有了 4 个空格,您就有:

droggel:
    jug:
        - sequence item: with indentation
          this line: isn't aligned to four spaces
          nor are further indented lines:
               if you indent relative four spaces
    spam:
    - same: problem
      without: indenting the sequence item

这使得代码格式化程序很难正确处理。正确对齐意味着:

droggel:
    jug:
        -   three spaces after the sequence item indicator.
            that's horrible, nobody does that.
    spam:
      - alternatively this.
        nobody does this either and it breaks
      - - with nested sequences

我认为 IntelliJ 中的一些错误会导致格式化程序因此而混乱。一般来说,最好只使用 2 个空格缩进,由于上述问题,这看起来更自然。这应该避免混淆格式化程序。


0
投票

有一个修复列表值的配置。在编辑器->代码样式->Yaml中

"Indent sequence value"
© www.soinside.com 2019 - 2024. All rights reserved.