intellij-hcl icon indicating copy to clipboard operation
intellij-hcl copied to clipboard

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

Open nlowe opened this issue 6 years ago • 4 comments

Prerequisites

  • [x] Ensure you have latest version of plugin installed
  • [x] Search for possible issue duplicates

Installation details

  • [x] IDE version (Help->About->Copy to Clipboard)
    GoLand 2018.3.4
    Build #GO-183.5429.49, built on February 12, 2019
    Licensed to Hyland Software Inc. / Nathan Lowe
    Subscription is active until November 17, 2019
    JRE: 1.8.0_152-release-1343-b26 amd64
    JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
    Windows 10 10.0
    
  • [x] intellij-hcl plugin version (Settings->Plugins)
    • v0.6.13
  • [x] Terraform version (terraform -v)
    • Terraform v0.11.11

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.

nlowe avatar Feb 18 '19 20:02 nlowe

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

VladRassokhin avatar Feb 19 '19 11:02 VladRassokhin

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

nlowe avatar Feb 19 '19 16:02 nlowe

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

mattdillon100 avatar Aug 30 '19 02:08 mattdillon100

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.

aingham avatar Jun 25 '21 11:06 aingham