JamesWoolfenden/ghat

Respect comments and whitespace outside terraform blocks

dylan-hoefsloot opened this issue · 1 comments

Is your feature request related to a problem? Please describe.
When using swipe to replace references in a terraform file, any whitespace and comments outside modules terraform blocks are removed.

Describe the solution you'd like
Respect existing whitespace and comments

Describe alternatives you've considered
Manually revert/unstage unwanted formatting changes (this is fine, just time consuming on larger projects).

Additional context
For example, this file input:

# This is a comment
resource "type" "name" {
  key = "value"
  
  # Comment in block
  another_key = "another_value"
}

resource "another_type" "another_name" {
  key = "value"
}

becomes this output:

resource "type" "name" {
  key = "value"

  # Comment in block
  another_key = "another_value"
}
resource "another_type" "another_name" {
  key = "value"
}

as you can see the whitespace and comments within the block is respected but anything outside is removed.

Hi @dylan-hoefsloot I know this issue, will take a look when i have the time.