Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

EmbDoc fixes #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2023
Merged
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
31 changes: 29 additions & 2 deletions lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4090,7 +4090,8 @@ def deconstruct_keys(_keys)
def format(q)
q.group do
q.group do
q.text("def ")
q.text("def")
q.text(" ") if target || name.comments.empty?

if target
q.format(target)
Expand Down Expand Up @@ -4872,6 +4873,25 @@ class EmbDoc < Node
def initialize(value:, location:)
@value = value
@location = location

@leading = false
@trailing = false
end

def leading!
@leading = true
end

def leading?
@leading
end

def trailing!
@trailing = true
end

def trailing?
@trailing
end

def inline?
Expand Down Expand Up @@ -4908,7 +4928,13 @@ def deconstruct_keys(_keys)
end

def format(q)
q.trim
if (q.parent.is_a?(DefNode) && q.parent.endless?) ||
q.parent.is_a?(Statements)
q.trim
else
q.breakable_return
end

q.text(value)
end

Expand Down Expand Up @@ -10465,6 +10491,7 @@ def deconstruct_keys(_keys)

def format(q)
q.text(":")
q.text("\\") if value.comments.any?
q.format(value)
end

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@
%
a b do
end.c d
%
self.
=begin
=end
to_s
16 changes: 16 additions & 0 deletions test/fixtures/def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ def foo() # comment
def foo( # comment
)
end
%
def
=begin
=end
a
end
%
def a()
=begin
=end
=1
-
def a() =
=begin
=end
1
5 changes: 5 additions & 0 deletions test/fixtures/symbols.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@
%I[foo] # comment
%
%I{foo[]}
%
:\
=begin
=end
symbol