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

Commit 7a58e81

Browse files
committed
Format comments on params even if they are empty
1 parent 65d643d commit 7a58e81

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/syntax_tree/node.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,7 +3053,10 @@ def format(q)
30533053
q.group do
30543054
q.text("def ")
30553055
q.format(name)
3056-
q.format(params) if !params.is_a?(Params) || !params.empty?
3056+
3057+
if !params.is_a?(Params) || !params.empty? || params.comments.any?
3058+
q.format(params)
3059+
end
30573060
end
30583061

30593062
unless bodystmt.empty?
@@ -3273,7 +3276,10 @@ def format(q)
32733276
q.format(target)
32743277
q.format(CallOperatorFormatter.new(operator), stackable: false)
32753278
q.format(name)
3276-
q.format(params) if !params.is_a?(Params) || !params.empty?
3279+
3280+
if !params.is_a?(Params) || !params.empty? || params.comments.any?
3281+
q.format(params)
3282+
end
32773283
end
32783284

32793285
unless bodystmt.empty?
@@ -6310,16 +6316,16 @@ def format(q)
63106316
q.format(rest) if rest && rest.is_a?(ExcessedComma)
63116317
end
63126318

6313-
if [Def, Defs, DefEndless].include?(q.parent.class)
6319+
if ![Def, Defs, DefEndless].include?(q.parent.class) || parts.empty?
6320+
q.nest(0, &contents)
6321+
else
63146322
q.group(0, "(", ")") do
63156323
q.indent do
63166324
q.breakable("")
63176325
contents.call
63186326
end
63196327
q.breakable("")
63206328
end
6321-
else
6322-
q.nest(0, &contents)
63236329
end
63246330
end
63256331
end
@@ -8387,8 +8393,6 @@ def format(q)
83878393
q.text(")")
83888394
elsif ternary
83898395
q.if_break {}.if_flat { q.text(")") }
8390-
else
8391-
q.text(" ")
83928396
end
83938397
end
83948398
end

0 commit comments

Comments
 (0)