Skip to content

Spaces around comment and trailing commas are missing in output from hcl2.writes #278

@irene-picnic

Description

@irene-picnic

Describe the bug

import sys
import hcl2

print(hcl2.writes(hcl2.parse(sys.stdin))

Running the above code on the following snippet

locals {
  foo = "bar" # Foo
  baz = "biz"
  spam = egg([
    "arg-1",
    "arg-2",
  ])
}

produces the following output.

locals {
  foo = "bar"# Foo
baz = "biz"
  spam = egg([
    "arg-1",
    "arg-2"
  ])
}

The issues are:

  • Spaces around the comment are no longer present.
  • Trailing comma is missing in the array.

Software:

  • OS: Linux
  • Python version: 3.13.12
  • python-hcl2 version: 7.3.1

Snippet of HCL2 code causing the unexpected behaviour:

locals {
  foo = "bar" # Foo
  baz = "biz"
  spam = egg([
    "arg-1",
    "arg-2",
  ])
}

Expected behavior

The exact input is produced since the AST is not modified.

Exception traceback (if applicable):

N/A

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions