-
Notifications
You must be signed in to change notification settings - Fork 599
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: Allow blank quoted string block labels #422
Conversation
The hclsyntax package permits block labels to be blank quoted strings, and defers to the application to determine if this is valid or not. This commit updates hclwrite to allow the same behaviour. This is in response to an upstream bug report on Terraform, which uses hclwrite to implement its fmt subcommand. Given a block with a blank quoted string label, it currently deletes the label when formatting. This is inconsistent with Terraform's behaviour when parsing HCL, which treats empty labels differently from missing labels.
@@ -414,7 +421,7 @@ func TestBlockSetLabels(t *testing.T) { | |||
{ | |||
`foo "hoge" /* foo */ "" {}`, | |||
"foo", | |||
[]string{"hoge"}, | |||
[]string{"hoge", ""}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this test is covering the parsing of foo "hoge" "" {}
as foo "hoge" {}
, but it is an example of the bug we are trying to fix with this change, so I've updated the test. @minamijoyo, do you have any concerns about this test update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alisdair I'm not sure why 🤔
I checked the commit history and found that the test case was added by @apparentlymart
7e5b148
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 Sorry, my mistake! I misread the commit history. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm sorry about that! I imagine I must've misread the input while I was updating this (empty quotes in that position are unusual!) and managed to accidentally write a test that incorrectly passed, rather than a test that caught the bug. 😖
My main goal here was to test the handling of that comment in the middle, so I expect I was focused on it having removed that and not paying attention to how it handled the labels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable to me - I always favor consistency - but it might be a good idea to check in with @apparentlymart and see if there's a specific reason fmt
handles it differently.
The
hclsyntax
package permits block labels to be blank quoted strings, and defers to the application to determine if this is valid or not. This commit updateshclwrite
to allow the same behaviour.This is in response to an upstream bug report on Terraform, which uses
hclwrite
to implement itsfmt
subcommand. Given a block with a blank quoted string label, it currently deletes the label when formatting. This is inconsistent with Terraform's behaviour when parsing HCL, which treats empty labels differently from missing labels:I've confirmed that incorporating this change into Terraform fixes the upstream bug.