VladRassokhin / intellij-hcl

HCL language support for IntelliJ platform based IDEs
Apache License 2.0
244 stars 47 forks source link

No option to place closing bracket on new line when wrapping or chopping long arrays #196

Open nlowe opened 5 years ago

nlowe commented 5 years ago

Prerequisites

Installation details

Terraform Configuration Files

variable "foo" {
    type    = "list"
    default = ["a", "b", "c"]
}

Expected Behavior

When the default array (or any array in general) gets too long and Chop down if long is set in formatting settings, or if Wrap Always is set in formatting settings, I expect the above code to be reformatted as follows:

variable "foo" {
    type    = "list"
    default = [
        "a",
        "b",
        "c"
    ]
}

Actual Behavior

The code is reformatted as follows:

variable "foo" {
    type    = "list"
    default = [
        "a",
        "b",
        "c"]
}

Note the closing ] stays on the same line as the last element.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Install the Terraform / HCL Plugin
  2. In Settings > Editor > Code Style > Terraform Config, under the Wrapping and Braces tab, set Arrays to Wrap Always.
  3. Write the above hcl to vars.tf
  4. Re-format the document (Ctrl+Alt+Shift+L)

Notes

Other languages have the ability to control where the closing ] gets places. For example, Javascript:

image

I found this because the rest of my team works with terraform manifests in VSCode. I was trying to get the formatting to match.

VladRassokhin commented 5 years ago

For now it's recommended to configure terraform fmt file watcher and also performing it before committing changes.

nlowe commented 5 years ago

Ah, I didn't know that was a thing. That's exactly what I'm looking for!

mattdillon100 commented 5 years ago

I have the terraform fmt file watcher running but this bug is still very annoying. Is there a timeline on a fix?

aingham commented 3 years ago

This is annoying me as well! The problem with using terraform fmt is that it formats a whole directory, rather than the specific file you're working with?

Also, I found that using terraform fmt, the closing ']' stays on the same line as the last element as well! Seems odd, but there you go.