Home > Mobile >  Intellij is incorrectly formatting my `.yml` file, I cannot see any errors in my style settings. how
Intellij is incorrectly formatting my `.yml` file, I cannot see any errors in my style settings. how

Time:02-22

Intellij keeps formatting my spotbugs.yml file incorrectly, and so breaking the github action.
I cannot figure out why it's doing this:

enter image description here

It was working fine last week, I haven't made any changes to the formatting config, but now, every time I change focus from the file Intellij auto-formats like this, then saves it. How can I fix it?

The thing I don't get is what it's formatting to appears to be invalid yaml, right?

CodePudding user response:

YAML has a syntax that makes it incompatible with indentation that is not 2 spaces. With 4 spaces, you have:

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

This makes it hard for code formatters to get it right. Proper alignment would mean:

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

I assume some bug in IntelliJ causes the formatter to be confused because of this. Generally it would be better to just use 2 space indentation which seems far more natural due to the problems described above. That should avoid confusing the formatter.

  • Related