From 0a1135d11e161b2795c840fbac7ec95c14436b06 Mon Sep 17 00:00:00 2001 From: vaclavbohac Date: Mon, 10 Jun 2024 12:34:33 +0200 Subject: [PATCH] Allow 'empty line' comments --- lib/graphql/language/comment.rb | 6 +++--- lib/graphql/language/parser.rb | 2 +- spec/graphql/language/printer_spec.rb | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/graphql/language/comment.rb b/lib/graphql/language/comment.rb index 612829ece5..a1064399bf 100644 --- a/lib/graphql/language/comment.rb +++ b/lib/graphql/language/comment.rb @@ -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 diff --git a/lib/graphql/language/parser.rb b/lib/graphql/language/parser.rb index e6e15c8f83..728a23c030 100644 --- a/lib/graphql/language/parser.rb +++ b/lib/graphql/language/parser.rb @@ -721,7 +721,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 diff --git a/spec/graphql/language/printer_spec.rb b/spec/graphql/language/printer_spec.rb index 46180ae9bf..7a5fb0560e 100644 --- a/spec/graphql/language/printer_spec.rb +++ b/spec/graphql/language/printer_spec.rb @@ -151,6 +151,7 @@ Scalar description """ # Scalar comment + # # Multiline scalar CustomScalar