hclwrite: handle legacy dot access of numeric indexes #369
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR allows
hclwriter
to handle dot syntax for index accesses, e.g.:Previously, attempting to partition on an open bracket caused a panic:
https://github.com/hashicorp/hcl/blob/hcl2/hclwrite/parser.go#L408
This PR adds a
PartitionTypeOk
that is a copy ofPartitionType
. It returns the same values, plus anok
bool signifying that the token type was found. Otherwise, it returns zero-valueinputTokens
objects and afalse
boolean indicating that a partition token could not be found.The approach to detecting that a traversal is
.#
style is admittedly fairly naive. However, adding a passing test ona = foo[bar.baz]
makes me feel a bit more confident.Related bug reports:
apparentlymart/terraform-clean-syntax#5
bendrucker/terraform-cloud-migrate#3
I tested a copy of this patch and confirmed that it resolves the second report.
Thank you for all your work here, it has been a joy to develop on! Looking forward to contributing more.