diff --git a/changelog/fix_undefined_method_range_between.md b/changelog/fix_undefined_method_range_between.md new file mode 100644 index 000000000000..b079fbc292bc --- /dev/null +++ b/changelog/fix_undefined_method_range_between.md @@ -0,0 +1 @@ +* [#11405](https://github.com/rubocop/rubocop/issues/11405): Fix undefined method `range_between' for Style/WhileUntilModifier. ([@such][]) diff --git a/lib/rubocop/cop/mixin/statement_modifier.rb b/lib/rubocop/cop/mixin/statement_modifier.rb index f3757dc22dd1..4755c4a6af68 100644 --- a/lib/rubocop/cop/mixin/statement_modifier.rb +++ b/lib/rubocop/cop/mixin/statement_modifier.rb @@ -5,6 +5,7 @@ module Cop # Common functionality for modifier cops. module StatementModifier include LineLengthHelp + include RangeHelp private diff --git a/spec/support/condition_modifier_cop.rb b/spec/support/condition_modifier_cop.rb index 354a6fa4d85b..41c3a818982c 100644 --- a/spec/support/condition_modifier_cop.rb +++ b/spec/support/condition_modifier_cop.rb @@ -17,6 +17,19 @@ RUBY end + it 'accepts it if single line would not fit on one line and body last argument is a hash type with value omission', :ruby31 do + # This statement is one character too long to fit. + condition = 'a' * (40 - keyword.length) + body = "#{'b' * 35}(a:)" + expect("#{body} #{keyword} #{condition}".length).to eq(81) + + expect_no_offenses(<<~RUBY) + #{keyword} #{condition} + #{body} + end + RUBY + end + context 'when Layout/LineLength is disabled' do let(:other_cops) { { 'Layout/LineLength' => { 'Enabled' => false } } }