Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,16 @@ func (f *fumpter) applyPre(c *astutil.Cursor) {
}
}
// If none of the comment group's lines look like a
// directive or code, add spaces, if needed.
// directive or code, add or remove spaces, as appropriate.
for _, comment := range group.List {
body := strings.TrimPrefix(comment.Text, "//")
r, _ := utf8.DecodeRuneInString(body)
if !unicode.IsSpace(r) {
if unicode.IsSpace(r) {
body = strings.TrimLeftFunc(body, unicode.IsSpace)
if rxCommentDirective.MatchString(body) {
comment.Text = "//" + body
}
} else {
comment.Text = "// " + body
}
}
Expand Down
4 changes: 4 additions & 0 deletions testdata/script/comment-spaced.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ package p

//noinspection foo,bar

// directive:withleadingspace

//not actually: a directive

//https://just.one/url
Expand Down Expand Up @@ -99,6 +101,8 @@ package p

//noinspection foo,bar

//directive:withleadingspace

// not actually: a directive

// https://just.one/url
Expand Down
Loading