Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform fmt adds extra lines in comment blocks #6375

Closed
BrianHicks opened this issue Apr 27, 2016 · 4 comments
Closed

terraform fmt adds extra lines in comment blocks #6375

BrianHicks opened this issue Apr 27, 2016 · 4 comments

Comments

@BrianHicks
Copy link
Contributor

Terraform Version

$ terraform -v
Terraform v0.6.15

Affected Resource(s)

n/a

Terraform Configuration Files

# this is a long comment block spanning multiple lines. I would expect
# `terraform fmt` to keep the lines together, but it doesn't.

Debug Output

https://gist.github.com/BrianHicks/45196caa7824eb6758ea071ecf2974b0

Expected Behavior

The comment block should have been left intact, as in the sample above.

Actual Behavior

Actual output:

# this is a long comment block spanning multiple lines. I would expect


# `terraform fmt` to keep the lines together, but it doesn't.

All newlines included.

Steps to Reproduce

  1. paste the above configuration into x.tf
  2. run terraform fmt x.tf
  3. observe the resulting file contents

Important Factoids

Installed via homebrew

References

Couldn't find any.

@dcarley
Copy link
Contributor

dcarley commented Apr 27, 2016

There's an issue and PR in the upstream parser for this:

@dangerp
Copy link

dangerp commented Apr 27, 2016

I ran into this issue as well, and I found a fairly simple workaround. For any multiline comments that are not attached to a resource (meaning there is an empty line between the comment and the resource), simply use the HCL syntax for a multiline comment instead of multiple single line comments. For example, instead of

# this is a long comment block spanning multiple lines. I would expect
# `terraform fmt` to keep the lines together, but it doesn't.

do this instead:

/*
this is a long comment block spanning multiple lines. I would expect
`terraform fmt` to keep the lines together, but it only does so if you use 
proper multiline comment syntax
*/

As far as I can tell, the hcl printer is treating each standalone comment line as a separate comment, therefore they are separated by empty lines. I would still consider this a bug in hcl, but at least I can use terraform fmt without spurious empty lines being added.

@mitchellh
Copy link
Contributor

This is fixed!

@ghost
Copy link

ghost commented Apr 21, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants