Skip to content

Commit

Permalink
hclwrite: Fix formatting of namespaced functions
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Feb 15, 2024
1 parent e28daa3 commit d703862
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hclwrite/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ func spaceAfterToken(subject, before, after *Token) bool {
// Don't split a function name from open paren in a call
return false

case (subject.Type == hclsyntax.TokenIdent && after.Type == hclsyntax.TokenDoubleColon) ||
(subject.Type == hclsyntax.TokenDoubleColon && after.Type == hclsyntax.TokenIdent):
// Don't split namespace segments in a function call
return false

case subject.Type == hclsyntax.TokenDot || after.Type == hclsyntax.TokenDot:
// Don't use spaces around attribute access dots
return false
Expand Down
4 changes: 4 additions & 0 deletions hclwrite/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,10 @@ module "x" {
abcde = "456"
}`,
},
{
`attr = provider::framework::example()`,
`attr = provider::framework::example()`,
},
}

for i, test := range tests {
Expand Down

0 comments on commit d703862

Please sign in to comment.