-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hclwrite: parser inserts an unexpected TokenNewline before a TokenCParen #402
Comments
If I swap the following lines, it seems to fix the issue and pass all existing tests. Lines 281 to 284 in bf0a7fe
However, I'm not sure if we can simply swap those because the comment says:
|
… on expression lines Reproducing example: the following snippet, the newline will preceed the closing parethesis, rewriting the parsed hcl will place it in the same line as `strategy`: ``` resource "kubernetes_deployment" "k" { spec { replicas = true ? 0 : (false ? 1 : 2) strategy { type = "whatever" } } } ```
created pr #408 , forked in the mean time, seems to be working for us |
Thanks for reporting this, @minamijoyo! I've not looked closely at the implementation here but based on experience with some similar bugs I expect this problem has as a root cause that the underlying When we fixed some similar problems to this in the past we changed the |
@apparentlymart if it helps, i've traced through the code multiple times, specifically on the example here below (the relevant line is "replicas".
|
@apparentlymart Thank you for the hints. I'm reading Line 918 in bf0a7fe
Actually the expression contains only
If my understanding is correct, we need to fix |
Looks like this bug may be expressed in the latest Cross-posting my related ticket for 0.14.0 here for reference: hashicorp/terraform#27040 UPDATE: on reading more closely the above thread, it looks like @shlomimatichin has a possible resolution path in PR: #408 Unclear if that fix is confirmed or still wip. |
I confirmed that this issue was fixed by #426 in v2.8.0. Thanks to @apparentlymart @aaronsteers @shlomimatichin 🎉 |
Fixes #24 The upstream issue was fixed in hcl v2.8.0 hashicorp/hcl#402
Fixes #24 The upstream issue was fixed in hcl v2.8.0 hashicorp/hcl#402 All we need is updating hcl to v2.8.0
If an expression ends with a
TokenCParen
, thehclwrite
parser inserts an unexpectedTokenNewline
before aTokenCParen
.This issue was originally reported in minamijoyo/tfupdate#24,
but I found the root cause of this problem was in the upstream
hcl
library.HCL Template
Expected behavior
Parse HCL with
hclwrite.ParseConfig()
, then Generate HCL with(*File).BuildTokens(nil)
should be idempotent.Actual behavior
the
hclwrite
parser inserts an unexpectedTokenNewline
before aTokenCParen
.The
TokenNewline
should be inserted after theTokenCParen
not before it.The output is broken. (invalid syntax)
Steps to reproduce
go.mod
andmain.go
go run main.go
References
minamijoyo/tfupdate#24
The text was updated successfully, but these errors were encountered: