Skip to content
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
Fix #234
  • Loading branch information
kddnewton committed Dec 28, 2022
commit e5dde653f9cbe9ede5f183d9adb5f0efb01e8816
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