fix(terraform): count string literals so /* inside a glob is not a comment - #744
Merged
boyter merged 1 commit intoAug 11, 2026
Merged
Conversation
…mment
Terraform (an HCL dialect) declared an empty quotes list, unlike the HCL
entry which declares the "..." string literal. With no string rule a value
such as "logs/*" was parsed as code: the embedded /* opened a block comment
that ran to the next */ or to EOF, swallowing every following line as a
comment.
variable "glob" {
default = "logs/*"
}
output "result" {
value = "still real code"
}
master reports 6 lines / 2 code / 4 comments; after the fix 6 lines / 6 code
/ 0 comments. Add the single "..." quote rule that HCL already carries and
regenerate processor/constants.go. Regression test asserts the glob case.
Owner
|
Cheers |
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.
Problem
Terraform(an HCL dialect) declares an emptyquoteslist, unlike theHCLlanguage entry which declares the"..."string literal. With no string rule, a value such as"logs/*"is parsed as code: the embedded/*opens a block comment that runs to the next*/or to EOF, swallowing every following line as a comment.On master this reports 6 lines / 2 code / 4 comments — the
}and the wholeoutputblock are miscounted as comments. Globs like"logs/*"are common in Terraform (ignore_changes,for_eachfilters, path variables).Fix
Add the single
"..."quote rule thatHCLalready carries, then regenerateprocessor/constants.go. No other language is touched.Test plan
go test ./...— green, including a newTestCountStatsTerraformGlobStringNotCommentthat feeds the glob above and asserts6 lines / 6 code / 0 comments / 0 blanks. On master the same input returns4 comments(the test fails); with the fix it returns0 comments.I licence this contribution under the MIT licence.