Skip to content

Fix #234 #237

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
Dec 28, 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
10 changes: 5 additions & 5 deletions lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6160,7 +6160,7 @@ def call(q, node)
# want to force it to not be a ternary, like if the predicate is an
# assignment because it's hard to read.
case node.predicate
when Assign, Command, CommandCall, MAssign, OpAssign
when Assign, Binary, Command, CommandCall, MAssign, OpAssign
return false
when Not
return false unless node.predicate.parentheses?
Expand All @@ -6183,10 +6183,10 @@ def call(q, node)
# and default instead to breaking them into multiple lines.
def ternaryable?(statement)
case statement
when AliasNode, Assign, Break, Command, CommandCall, Heredoc, IfNode,
IfOp, Lambda, MAssign, Next, OpAssign, RescueMod, ReturnNode,
Super, Undef, UnlessNode, UntilNode, VoidStmt, WhileNode,
YieldNode, ZSuper
when AliasNode, Assign, Break, Command, CommandCall, Defined, Heredoc,
IfNode, IfOp, Lambda, MAssign, Next, OpAssign, RescueMod,
ReturnNode, Super, Undef, UnlessNode, UntilNode, VoidStmt,
WhileNode, YieldNode, ZSuper
# This is a list of nodes that should not be allowed to be a part of a
# ternary clause.
false
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/if.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@
if true # comment1
# comment2
end
%
result =
if false && val = 1
"A"
else
"B"
end