Skip to content
Closed
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
16 changes: 15 additions & 1 deletion lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4388,8 +4388,22 @@ def forced_brace_bounds?(q)
when Paren, Statements
# If we hit certain breakpoints then we know we're safe.
return false
when IfNode, IfOp, UnlessNode, WhileNode, UntilNode
when IfNode, IfOp, UnlessNode
# If this node is the predicate of an if/unless node, then we're
# going to have to use the {..} bounds.
return true if parent.predicate == previous
when WhileNode, UntilNode
if previous.is_a?(Binary)
# If this node is the predicate of a while/until node, then we're
# going to have to use the {..} bounds if the loop is in the
# modifier form because otherwise the do/end could be confused for
# the optional do keyword of the loop.
return parent.predicate == previous && parent.modifier?
else
# If this node is the predicate of a while/until node, then we're
# going to have to use the {..} bounds.
return true if parent.predicate == previous
end
end

previous = parent
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,17 @@
-
foo *
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
%
foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
%
foooooooooooooooooooooo && barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foooooooooooooooooooooo &&
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end