From e8e5d9a8262287045cf32606d29cd069423bc1c1 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Thu, 20 Aug 2026 16:27:48 -0400 Subject: [PATCH] Avoid parentheses around block expressions --- lib/rubocop/cop/type_toolkit/prefer_not_nil.rb | 1 - spec/rubocop/cop/type_toolkit/prefer_not_nil_spec.rb | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/rubocop/cop/type_toolkit/prefer_not_nil.rb b/lib/rubocop/cop/type_toolkit/prefer_not_nil.rb index effefd4..d3d283d 100644 --- a/lib/rubocop/cop/type_toolkit/prefer_not_nil.rb +++ b/lib/rubocop/cop/type_toolkit/prefer_not_nil.rb @@ -90,7 +90,6 @@ def requires_parentheses?(argument) end return true if argument.range_type? || argument.operator_keyword? return true if argument.if_type? || argument.assignment? - return true if argument.any_block_type? KEYWORD_EXPRESSION_TYPES.include?(argument.type) end diff --git a/spec/rubocop/cop/type_toolkit/prefer_not_nil_spec.rb b/spec/rubocop/cop/type_toolkit/prefer_not_nil_spec.rb index 0f9badc..5629727 100644 --- a/spec/rubocop/cop/type_toolkit/prefer_not_nil_spec.rb +++ b/spec/rubocop/cop/type_toolkit/prefer_not_nil_spec.rb @@ -77,6 +77,8 @@ class PreferNotNilSpec < ::Minitest::Spec ^^^^^^^^^^^^^^^^^ #{MSG} block_value = T.must(foo { bar }) ^^^^^^^^^^^^^^^^^^^ #{MSG} + block_with_arguments = T.must(foo(arg) { |value| value }) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{MSG} defined_value = T.must(defined?(foo)) ^^^^^^^^^^^^^^^^^^^^^ #{MSG} def example @@ -98,7 +100,8 @@ def explicit_super logical = (foo || bar).not_nil! grouped = (foo || bar).not_nil! assignment = (foo = bar).not_nil! - block_value = (foo { bar }).not_nil! + block_value = foo { bar }.not_nil! + block_with_arguments = foo(arg) { |value| value }.not_nil! defined_value = (defined?(foo)).not_nil! def example (yield foo).not_nil!