Repository navigation
hclwrite: find traversals inside object-construct expressions - #841
Merged
Merged
Conversation
Since hashicorp#810, parseObjectConsExpr parses each item's key and value into its own Expression, so the object's wrapping Expression held no traversals, Expression.Variables returned nothing for it and RenameVariablePrefix left it unchanged. Walk the items so both see the keys' and values' traversals in source order. A naked identifier key is a literal, as in hclsyntax, so its traversal is dropped at parse time.
|
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Have you signed the CLA already but the status is still pending? Recheck it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Since #810,
parseObjectConsExprparses each item's key and value into its ownExpression, so the object's wrappingExpressionholds no traversals,Expression.Variablesreturns nothing for it andRenameVariablePrefixleaves it unchanged. This walks the object's items so both see the keys' and values' traversals in source order. A naked identifier key is a literal, as in hclsyntax, so its traversal is dropped at parse time and is neither reported nor renamed.Related Issue
Fixes #840.
How Has This Been Tested?
TestExpressionVariablesObjectConscovers nine object shapes and checks that hclwrite reports the same variable count as hclsyntax for each. Seven of the nine cases fail on main at 4932c14 and all pass with this change.go test -race ./...,make checkand golangci-lint v2.5.0 pass.