tflint: Add workaround to get the range of configs.mergeBody
#1019
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.
tflint.HCLBodyRange
is used to get the start position of the range in order to sendhcl.Body
to plugins. This implementation uses the filename extension to determine if it's native or JSON syntax, and gets each one in a rather unintuitive way.However, there is a big problem with this assumption. First,
hclsyntax.Body
is not the only struct that satisfieshcl.Body
in the.tf
file. This method receivesconfigs.mergeBody
if resources were overridden.Handling merged bodies is very difficult with the current implementation. First,
tflint.HCLBodyRange
should not return a single range, as it consists of multiple files and ranges. This PR changes the implementation to return an empty range for avoiding panicI understand that this is not reasonable. However, while it is possible in native syntax to return some warning instead of returning an empty range, JSON syntax cannot even determine if it is merged body because the struct is private. I believe this change is the best way with minimal changes.
In the future, I plan to solve this inconvenience by changing the plugin interface. See also terraform-linters/tflint-plugin-sdk#89