terraform icon indicating copy to clipboard operation
terraform copied to clipboard

terraform fmt should add an empty line at the end of the file

Open ralbertazzi opened this issue 6 years ago • 3 comments
trafficstars

Current Terraform Version

0.12.12

Proposal

It's usually a good practice in many languages to have an empty line at the end of the file. Formatters like black for Python or prettier for JavaScript take care of that. terraform fmt should do the same.

Notice also that GitHub counts the missing empty line as a small error in pull requests, adding a small symbol at the end of the file when you review the changed files.

ralbertazzi avatar Oct 29 '19 13:10 ralbertazzi

Hi @ralbertazzi,

terraform fmt currently concerns itself primarily with horizontal whitespace: indentation and alignment. It currently preserves vertical whitespace (newlines) as-is. The rationale for this is that horizontal alignment is generally more difficult/tedious for humans to address manually, while adding and removing newlines is relatively easier to do and often done for subjective reasons that an automatic tool cannot reason about (though the case you are describing is not an example of that).

We don't have any plans to change that in the near future, because changes to terraform fmt tend to be disruptive to automated systems. While we might reconsider this in future, we'd prefer to do it as part of a more significant set of changes made at once, made in a major release so it's easier for automated systems to adapt to the new changes.

In the meantime, you can feel free to end all of your files with a newline yourself, or have your editor do so automatically, and terraform fmt should not remove it.

teamterraform avatar Oct 29 '19 16:10 teamterraform

https://github.com/hashicorp/terraform/issues/29677

stawii avatar Mar 10 '22 14:03 stawii

This could easily have been fixed in terraform 1.0. Please fix this in the next major release (2.0?).

olivers-xaxis avatar Apr 14 '23 13:04 olivers-xaxis