hashicorp / hcl2

Former temporary home for experimental new version of HCL
https://github.com/hashicorp/hcl
Mozilla Public License 2.0
373 stars 66 forks source link

Support HCL1-style single-line one-argument block #64

Closed apparentlymart closed 5 years ago

apparentlymart commented 5 years ago

HCL1 supported a special single-line block form when only one argument was present:

foo { bar = baz }

This was initially excluded from the new language spec intentionally, but given how commonly this form is used in the wild with HCL1-based languages we should support it in HCL2 so it doesn't become another point of friction during a migration.

The specification should be updated to allow for a different form of block syntax where the opening brace is directly followed by an identifier, then the key = value can be parsed as normal and we'll require the closing brace to also appear on the same line. This is stricter than what was permitted in HCL1 but accepts the common idiom while only excluding degenerate forms such as having the closing brace on the next line or listing out more attributes no the following lines as if it were a multi-line block.

We also need to teach the formatter in hclwrite how to deal with this form, since it currently has no rules to deal with an opening brace with more content after it, or a closing brace that isn't on its own line.

apparentlymart commented 5 years ago

Implemented in bafa0c5ace186f6b3b1ed5c120ab5f11086b5bad.