Skip to content

Commit

Permalink
feat(formatter): preserve spaces at the head of comments (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
Warashi committed Jun 26, 2023
1 parent fd040d1 commit 35199fc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ast/comment.go
Expand Up @@ -11,7 +11,7 @@ type Comment struct {
}

func (c *Comment) Text() string {
return strings.TrimSpace(strings.TrimPrefix(c.Value, "#"))
return strings.TrimPrefix(c.Value, "#")
}

type CommentGroup struct {
Expand Down
2 changes: 1 addition & 1 deletion formatter/formatter.go
Expand Up @@ -726,5 +726,5 @@ func (f *formatter) FormatComment(comment *ast.Comment) {
if comment == nil {
return
}
f.WriteString("# ").WriteString(comment.Text()).WriteNewline()
f.WriteString("#").WriteString(comment.Text()).WriteNewline()
}
Empty file.
@@ -0,0 +1,5 @@
#no spaces at the head of comment
# one space at the head of comment
# two spaces at the head of comment
# one tab at the head of comment
# two tabs at the head of comment
5 changes: 5 additions & 0 deletions formatter/testdata/source/schema/comment.graphql
@@ -0,0 +1,5 @@
#no spaces at the head of comment
# one space at the head of comment
# two spaces at the head of comment
# one tab at the head of comment
# two tabs at the head of comment

0 comments on commit 35199fc

Please sign in to comment.