Skip to content

Commit

Permalink
[Fix #11405] Fix Style/WhileUntilModifier with ruby 3.1
Browse files Browse the repository at this point in the history
Fix crash when while/until body last argument is a hash with value omission
  • Loading branch information
such committed Jan 9, 2023
1 parent 3ce55d0 commit 1ac1ce7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/fix_undefined_method_range_between.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11405](/~https://github.com/rubocop/rubocop/issues/11405): Fix undefined method `range_between' for Style/WhileUntilModifier. ([@such][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/mixin/statement_modifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Cop
# Common functionality for modifier cops.
module StatementModifier
include LineLengthHelp
include RangeHelp

private

Expand Down
13 changes: 13 additions & 0 deletions spec/support/condition_modifier_cop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } } }

Expand Down

0 comments on commit 1ac1ce7

Please sign in to comment.