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

Commit 7fd2af3

Browse files
committed
Format comments on params even if they are empty
1 parent a576f84 commit 7fd2af3

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
@@ -3060,7 +3060,10 @@ def format(q)
30603060
q.group do
30613061
q.text("def ")
30623062
q.format(name)
3063-
q.format(params) if !params.is_a?(Params) || !params.empty?
3063+
3064+
if !params.is_a?(Params) || !params.empty? || params.comments.any?
3065+
q.format(params)
3066+
end
30643067
end
30653068

30663069
unless bodystmt.empty?
@@ -3280,7 +3283,10 @@ def format(q)
32803283
q.format(target)
32813284
q.format(CallOperatorFormatter.new(operator), stackable: false)
32823285
q.format(name)
3283-
q.format(params) if !params.is_a?(Params) || !params.empty?
3286+
3287+
if !params.is_a?(Params) || !params.empty? || params.comments.any?
3288+
q.format(params)
3289+
end
32843290
end
32853291

32863292
unless bodystmt.empty?
@@ -6317,16 +6323,16 @@ def format(q)
63176323
q.format(rest) if rest && rest.is_a?(ExcessedComma)
63186324
end
63196325

6320-
if [Def, Defs, DefEndless].include?(q.parent.class)
6326+
if ![Def, Defs, DefEndless].include?(q.parent.class) || parts.empty?
6327+
q.nest(0, &contents)
6328+
else
63216329
q.group(0, "(", ")") do
63226330
q.indent do
63236331
q.breakable("")
63246332
contents.call
63256333
end
63266334
q.breakable("")
63276335
end
6328-
else
6329-
q.nest(0, &contents)
63306336
end
63316337
end
63326338
end
@@ -8394,8 +8400,6 @@ def format(q)
83948400
q.text(")")
83958401
elsif ternary
83968402
q.if_break {}.if_flat { q.text(")") }
8397-
else
8398-
q.text(" ")
83998403
end
84008404
end
84018405
end

0 commit comments

Comments
 (0)