Skip to content

fix(terraform): count string literals so /* inside a glob is not a comment - #744

Merged
boyter merged 1 commit into
boyter:masterfrom
YuriNachos:YuriNachos/quick-tf-string-literals
Aug 11, 2026
Merged

fix(terraform): count string literals so /* inside a glob is not a comment#744
boyter merged 1 commit into
boyter:masterfrom
YuriNachos:YuriNachos/quick-tf-string-literals

Conversation

@YuriNachos

Copy link
Copy Markdown
Contributor

Problem

Terraform (an HCL dialect) declares an empty quotes list, unlike the HCL language 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.

variable "glob" {
  default = "logs/*"
}
output "result" {
  value = "still real code"
}

On master this reports 6 lines / 2 code / 4 comments — the } and the whole output block are miscounted as comments. Globs like "logs/*" are common in Terraform (ignore_changes, for_each filters, path variables).

Fix

Add the single "..." quote rule that HCL already carries, then regenerate processor/constants.go. No other language is touched.

Test plan

go test ./... — green, including a new TestCountStatsTerraformGlobStringNotComment that feeds the glob above and asserts 6 lines / 6 code / 0 comments / 0 blanks. On master the same input returns 4 comments (the test fails); with the fix it returns 0 comments.

I licence this contribution under the MIT licence.

…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.
@pr-insights pr-insights Bot added L/complexity Low complexity M/size Normal or medium sized change labels Aug 10, 2026
@boyter
boyter merged commit bcd6072 into boyter:master Aug 11, 2026
4 checks passed
@boyter

boyter commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L/complexity Low complexity M/size Normal or medium sized change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants