terraform icon indicating copy to clipboard operation
terraform copied to clipboard

`terraform fmt` doesn't break long lines

Open nhooey opened this issue 6 years ago • 5 comments

Terraform Version

Terraform v0.12.7

Expected Behavior

Running terraform fmt on a file should break long lines. A reasonable number could be 120 chars. Or it should have the option to configure the amount of chars to break on.

Actual Behavior

Long lines are left intact.

nhooey avatar Sep 05 '19 15:09 nhooey

anytime soon ?

halradaideh avatar Sep 28 '22 04:09 halradaideh

I'm concerned that this would potentially cause very large diffs on other lines due to terraform insisting on adding non meaningful whitespace in front of =.

For example:

variable "foo" {
  type    = string
  default = "A very long message that is reviewable in many PR tools and is reaching beyond the edge of many screens."
}

The default line is at 119 characters.

variable "foo" {
  type        = string
  default     = "A very long message that is reviewable in many PR tools and is reaching beyond the edge of many screens."
  description = "Simple message."
}

Now we are at 123 characters, so it would need to be broken up. I'm already very annoyed that PRs are now showing a diff for type and default which is a distraction, but now default itself becomes a multiline change, because some other line has changed. I know we can disable whitespace in most diff tools, but if the same PR has changes for python or yaml, disabling the whitespace diff is a very bad idea.

The example above is trivial but I had to deal with bunch of lines being re-aligned due to an other line being added/removed and this is a concrete issue.

It also makes the blame history much more verbose because we now have to sort out all the meaningless diffs when we want to track when a real value changed.

sodul avatar Aug 03 '23 23:08 sodul

two years update, anytime soon?

halradaideh avatar Jan 17 '24 06:01 halradaideh

No update. Please indicate your interest by adding a 👍 to the issue description. Thanks!

crw avatar Jan 17 '24 18:01 crw

I think this would be a major improvement. I currently have formatting options set in my IDE but this feature would be useful

RoseSecurity avatar Feb 06 '24 17:02 RoseSecurity