lib/rubocop/cop/style/ternary_parentheses.rb in rubocop-0.71.0 vs lib/rubocop/cop/style/ternary_parentheses.rb in rubocop-0.72.0

- old
+ new

@@ -106,11 +106,11 @@ NON_COMPLEX_TYPES.include?(condition.type) || non_complex_send?(condition) end def non_complex_send?(node) - return false unless node.send_type? + return false unless node.call_type? !node.operator_method? || node.method?(:[]) end def message(node) @@ -147,15 +147,25 @@ redundant_parentheses_enabled? end def unsafe_autocorrect?(condition) condition.children.any? do |child| - unparenthesized_method_call?(child) + unparenthesized_method_call?(child) || + below_ternary_precedence?(child) end end def unparenthesized_method_call?(child) method_name(child) =~ /^[a-z]/i && !child.parenthesized? + end + + def below_ternary_precedence?(child) + # Handle English "or", e.g. 'foo or bar ? a : b' + (child.or_type? && child.semantic_operator?) || + # Handle English "and", e.g. 'foo and bar ? a : b' + (child.and_type? && child.semantic_operator?) || + # Handle English "not", e.g. 'not foo ? a : b' + (child.send_type? && child.prefix_not?) end def_node_matcher :method_name, <<-PATTERN {($:defined? (send nil? _) ...) (send {_ nil?} $_ _ ...)}