Skip to content

Commit 35199fc

Browse files
authored
feat(formatter): preserve spaces at the head of comments (#265)
1 parent fd040d1 commit 35199fc

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

ast/comment.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Comment struct {
1111
}
1212

1313
func (c *Comment) Text() string {
14-
return strings.TrimSpace(strings.TrimPrefix(c.Value, "#"))
14+
return strings.TrimPrefix(c.Value, "#")
1515
}
1616

1717
type CommentGroup struct {

formatter/formatter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -726,5 +726,5 @@ func (f *formatter) FormatComment(comment *ast.Comment) {
726726
if comment == nil {
727727
return
728728
}
729-
f.WriteString("# ").WriteString(comment.Text()).WriteNewline()
729+
f.WriteString("#").WriteString(comment.Text()).WriteNewline()
730730
}

formatter/testdata/baseline/FormatSchema/comment.graphql

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#no spaces at the head of comment
2+
# one space at the head of comment
3+
# two spaces at the head of comment
4+
# one tab at the head of comment
5+
# two tabs at the head of comment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#no spaces at the head of comment
2+
# one space at the head of comment
3+
# two spaces at the head of comment
4+
# one tab at the head of comment
5+
# two tabs at the head of comment

0 commit comments

Comments
 (0)