Skip to content

Better formatting for array patterns in rassign #90

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
May 20, 2022
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
53 changes: 39 additions & 14 deletions lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,11 @@ def format(q)
q.group do
q.format(constant)
q.text("[")
q.seplist(parts) { |part| q.format(part) }
q.indent do
q.breakable("")
q.seplist(parts) { |part| q.format(part) }
end
q.breakable("")
q.text("]")
end

Expand All @@ -1141,7 +1145,11 @@ def format(q)
parent = q.parent
if parts.length == 1 || PATTERNS.include?(parent.class)
q.text("[")
q.seplist(parts) { |part| q.format(part) }
q.indent do
q.breakable("")
q.seplist(parts) { |part| q.format(part) }
end
q.breakable("")
q.text("]")
elsif parts.empty?
q.text("[]")
Expand Down Expand Up @@ -2777,10 +2785,17 @@ def format(q)
q.format(value)
q.text(" ")
q.format(operator)
q.group do
q.indent do
q.breakable
q.format(pattern)

case pattern
in AryPtn | FndPtn | HshPtn
q.text(" ")
q.format(pattern)
else
q.group do
q.indent do
q.breakable
q.format(pattern)
end
end
end
end
Expand Down Expand Up @@ -4573,16 +4588,26 @@ def deconstruct_keys(_keys)

def format(q)
q.format(constant) if constant
q.group(0, "[", "]") do
q.text("*")
q.format(left)
q.comma_breakable

q.seplist(values) { |value| q.format(value) }
q.comma_breakable
q.group do
q.text("[")

q.text("*")
q.format(right)
q.indent do
q.breakable("")

q.text("*")
q.format(left)
q.comma_breakable

q.seplist(values) { |value| q.format(value) }
q.comma_breakable

q.text("*")
q.format(right)
end

q.breakable("")
q.text("]")
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/rassign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@
-
foooooooooooooooooooooooooooooooooooooo =>
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
%
foo => [
ConstantConstantConstant,
ConstantConstantConstant,
ConstantConstantConstant,
ConstantConstantConstant,
ConstantConstantConstant
]