deprecated_index
: restore evaluation of JSON expressions
#101
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.
Background
#90 fixed the problem of duplicate emitted issues for nested expressions, since
WalkExpressions
visits them recursively for HCL files. In doing so, it both fixed a bug related to good JSON files (#100) and created a regression in detecting dot syntax usage in JSON. There was no test coverage so I'm only now noticing this in hindsight.Changes
This PR restores evaluation of JSON expressions, without reintroducing the bug described in #100. That issue seems to describe a case where
hclsyntax.LexExpression
is called on a raw range of source bytes:tflint-ruleset-terraform/rules/terraform_deprecated_index.go
Line 63 in 70051da
When this range has escaped quotes, which are valid in the surrounding context, the raw content is not valid HCL. Given the previous implementation a more correct approach for JSON expressions would require parsing as JSON at some level to parse the escaped quotes:
Since
WalkExpressions
is not recursive for JSON, we still need to callVariables()
. But from there we can then just pass each traversal to the existingcheckLegacyTraversalIndex()
function written for HCL, and it works!