hashicorp / hashicorp/hcl

Feature Request: Support pretty-printing collection types

Open
#732 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
5.8k
Forks
657
Avg merge
20h 36m
Merged PRs (30d)
6

Description

Dear all,

I would like to see `terraform fmt` support pretty-printing collection types. Currently I observe that internal `terraform fmt` code runs format passes on _fixed_ lines (please see [format.go](https://github.com/hashicorp/hcl/blob/main/hclwrite/format.go#L27C1-L27C33)). But I hope it can help me format variables of collection types (_list_, _set_, _map_), for instance

```hcl
variable "example_set" {
type = set(string)
default = ["foo", "bar", "dog", "cat", "jojo"]
}

# reformatted to =========================>

variable "example_set" {
type = set(string)
default = [
"foo",
"bar",
"dog",
"cat",
"jojo"
]
}
```

To my understanding, implementing this feature requires replacing the current `[]formatLine` with other data strucutres like linked lists to allow flexible line insertions.

I hope you can put my feature request on your radar! If you don't mind, I'm also willing to implement it if you agree.

Best regards,

Xulei

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with hclwrite/format.go, especially the current format passes and []formatLine structure used by terraform fmt. Compare the existing formatting behavior with the collection example in the issue; done means list, set, and map values can be formatted across multiple lines as shown.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.