Skip to content

Break and return false in forced_brace_bounds? when Parent is a Binary #143

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

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
2 changes: 1 addition & 1 deletion lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ def forced_brace_bounds?(q)
previous = nil
q.parents.any? do |parent|
case parent
when Paren, Statements
when Paren, Statements, Binary
# If we hit certain breakpoints then we know we're safe.
return false
when If, IfMod, IfOp, Unless, UnlessMod, While, WhileMod, Until,
Expand Down
2 changes: 1 addition & 1 deletion lib/syntax_tree/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,7 @@ def on_paren(contents)

# If we encounter a parse error, just immediately bail out so that our
# runner can catch it.
def on_parse_error(error, *)
def on_parse_error(error)
raise ParseError.new(error, lineno, column)
end
alias on_alias_error on_parse_error
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
21 changes: 21 additions & 0 deletions test/fixtures/if.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,24 @@
if true # comment1
# comment2
end
%
if foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
something
end
-
if foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
something
end
%
if barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
something
end
-
if barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
}
something
end
21 changes: 21 additions & 0 deletions test/fixtures/if_mod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@
-
foo =
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr if foo
%
foo = barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr if foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo =
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr if foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
%
foo = bar if foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo = bar if foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
%
foo = bar if barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo = bar if barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
}
21 changes: 21 additions & 0 deletions test/fixtures/ifop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,24 @@
foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo ?
break :
baz
%
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz } ? bar : baz
-
if barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
}
bar
else
baz
end
%
fooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz } ? bar : baz
-
if fooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
bar
else
baz
end
21 changes: 21 additions & 0 deletions test/fixtures/unless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,24 @@
unless true # comment1
# comment2
end
%
unless foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
something
end
-
unless foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
something
end
%
unless barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
something
end
-
unless barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
}
something
end
21 changes: 21 additions & 0 deletions test/fixtures/unless_mod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@
-
foo =
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr unless foo
%
foo = barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr unless foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo =
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr unless foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
%
foo = bar unless foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo = bar unless foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
%
foo = bar unless barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo = bar unless barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
}
21 changes: 21 additions & 0 deletions test/fixtures/until.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,24 @@
until true # comment1
# comment2
end
%
until foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
something
end
-
until foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
something
end
%
until barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
something
end
-
until barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
}
something
end
21 changes: 21 additions & 0 deletions test/fixtures/until_mod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@
-
foo =
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr until foo
%
foo = barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr until foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo =
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr until foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
%
foo = bar until foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo = bar until foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
%
foo = bar until barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo = bar until barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
}
21 changes: 21 additions & 0 deletions test/fixtures/while.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,24 @@
while true # comment1
# comment2
end
%
while foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
something
end
-
while foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
something
end
%
while barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
something
end
-
while barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
}
something
end
21 changes: 21 additions & 0 deletions test/fixtures/while_mod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@
-
foo =
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr while foo
%
foo = barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr while foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo =
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr while foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
%
foo = bar while foooooooooooooooooooooo || barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo = bar while foooooooooooooooooooooo ||
barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? do |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
end
%
foo = bar while barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar| bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz }
-
foo = bar while barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.any? { |bar|
bazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
}