Skip to content

Commit

Permalink
Allow 'empty line' comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vaclavbohac committed Jun 10, 2024
1 parent 68843a0 commit 62ea569
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/graphql/language/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module GraphQL
module Language
module Comment
def self.print(str, indent: '')
lines = []
str.split("\n") do |line|
lines = str.split("\n").map do |line|
comment_str = "".dup
comment_str << indent
comment_str << "# "
comment_str << line
lines << comment_str
comment_str.rstrip
end

lines.join("\n") + "\n"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/language/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def value
advance_token
NullValue.new(pos: pos, name: "null", filename: @filename, source: self)
when :COMMENT
val = @lexer.token_value.sub('# ', '')
val = @lexer.token_value.sub(/^#(\s+)?/, '')
advance_token
val
when :IDENTIFIER
Expand Down
1 change: 1 addition & 0 deletions spec/graphql/language/printer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
Scalar description
"""
# Scalar comment
#
# Multiline
scalar CustomScalar
Expand Down

0 comments on commit 62ea569

Please sign in to comment.