hashicorp / hashicorp/hcl

Parsed `hclsyntax.Body` has slightly different range depending on what type of comment is at the top

Open
#702 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
5.8k
Forks
657
Avg merge
20h 36m
Merged PRs (30d)
6

Description

I would expect this to print the same thing six times but the `/**/` seems to behave differently if it's on the first line.
```
false
true
true
true
true
true
```
```Go
package main

import (
"fmt"

"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
)

func containsInitialPos(content string) bool {
file, _ := hclsyntax.ParseConfig([]byte(content), "", hcl.InitialPos)
body, _ := file.Body.(*hclsyntax.Body)
return body.Range().ContainsPos(hcl.InitialPos)
}

func main() {
fmt.Println(containsInitialPos("/**/\ntarget{}"))
fmt.Println(containsInitialPos("#\ntarget{}"))
fmt.Println(containsInitialPos("//\ntarget{}"))
fmt.Println(containsInitialPos("\n/**/\ntarget{}"))
fmt.Println(containsInitialPos("\n#\ntarget{}"))
fmt.Println(containsInitialPos("\n//\ntarget{}"))
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.