Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Format comments on params even if they are empty
  • Loading branch information
kddnewton committed Apr 22, 2022
commit 7fd2af359590bfbab5cb96ac6e8932da19c5aa97
18 changes: 11 additions & 7 deletions lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3060,7 +3060,10 @@ def format(q)
q.group do
q.text("def ")
q.format(name)
q.format(params) if !params.is_a?(Params) || !params.empty?

if !params.is_a?(Params) || !params.empty? || params.comments.any?
q.format(params)
end
end

unless bodystmt.empty?
Expand Down Expand Up @@ -3280,7 +3283,10 @@ def format(q)
q.format(target)
q.format(CallOperatorFormatter.new(operator), stackable: false)
q.format(name)
q.format(params) if !params.is_a?(Params) || !params.empty?

if !params.is_a?(Params) || !params.empty? || params.comments.any?
q.format(params)
end
end

unless bodystmt.empty?
Expand Down Expand Up @@ -6317,16 +6323,16 @@ def format(q)
q.format(rest) if rest && rest.is_a?(ExcessedComma)
end

if [Def, Defs, DefEndless].include?(q.parent.class)
if ![Def, Defs, DefEndless].include?(q.parent.class) || parts.empty?
q.nest(0, &contents)
else
q.group(0, "(", ")") do
q.indent do
q.breakable("")
contents.call
end
q.breakable("")
end
else
q.nest(0, &contents)
end
end
end
Expand Down Expand Up @@ -8394,8 +8400,6 @@ def format(q)
q.text(")")
elsif ternary
q.if_break {}.if_flat { q.text(")") }
else
q.text(" ")
end
end
end
Expand Down