Skip to content
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: Fix formatting of namespaced functions #658

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 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 Expand Up @@ -452,9 +457,12 @@ func tokenBracketChange(tok *Token) int {
//
// lead: always present, representing everything up to one of the others
// assign: if line contains an attribute assignment, represents the tokens
// starting at (and including) the equals symbol
//
// starting at (and including) the equals symbol
//
// comment: if line contains any non-comment tokens and ends with a
// single-line comment token, represents the comment.
//
// single-line comment token, represents the comment.
radeksimko marked this conversation as resolved.
Show resolved Hide resolved
//
// When formatting, the leading spaces of the first tokens in each of these
// cells is adjusted to align vertically their occurences on consecutive
Expand Down
10 changes: 10 additions & 0 deletions hclwrite/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,16 @@ module "x" {
abcde = "456"
}`,
},
{
`attr = provider::framework::example()`,
radeksimko marked this conversation as resolved.
Show resolved Hide resolved
`attr = provider::framework::example()`,
},
{
// This is invalid syntax so formatting it with spaces
// does not have any meaning other than to make the fact more visible
`attr = provider::+example()`,
`attr = provider:: + example()`,
},
}

for i, test := range tests {
Expand Down
Loading