You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added in #10111 , Style/NumberedParametersLimit reports that more than one numbered parameter is used, when there is only one parameter used but it is "higher" than _1 e.g. _2.
For example, .group_by { _2 } causes an offense of
Avoid using more than 1 numbered parameter; 2 detected.
(but group_by { _1 } does not)
I suspect that the intention of the cop was to avoid using more than one numbered parameter in a single block (e.g. { _1 + _2 + _3 }), rather than a single reference to a not-first numbered parameter (e.g. { _2 }).
Expected behavior
No offense - a single parameter is used
Actual behavior
An offense was raised.
Steps to reproduce the problem
TargetRubyVersion must be (at least) 2.7. Then the following repro.rb:
grouped={a: 1,b: 1,c: 2}.group_by{_2}
gives:
$ rubocop --config =(echo -e "AllCops:\n TargetRubyVersion: 2.7") --debug --cache false --only Style/NumberedParametersLimit re
pro.rb
configuration from /tmp/zshJPIBdI
Default configuration from /Users/owenstephens/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rubocop-1.41.0/config/default.yml
Inspecting 1 file
Scanning /private/tmp/repro.rb
C
Offenses:
repro.rb:1:11: C: Style/NumberedParametersLimit: Avoid using more than 1 numbered parameter; 2 detected.
grouped = { a: 1, b: 1, c: 2 }.group_by { _2 }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 file inspected, 1 offense detected
Added in #10111 ,
Style/NumberedParametersLimit
reports that more than one numbered parameter is used, when there is only one parameter used but it is "higher" than_1
e.g._2
.For example,
.group_by { _2 }
causes an offense of(but
group_by { _1 }
does not)I suspect that the intention of the cop was to avoid using more than one numbered parameter in a single block (e.g.
{ _1 + _2 + _3 }
), rather than a single reference to a not-first numbered parameter (e.g.{ _2 }
).Expected behavior
No offense - a single parameter is used
Actual behavior
An offense was raised.
Steps to reproduce the problem
TargetRubyVersion
must be (at least) 2.7. Then the followingrepro.rb
:gives:
RuboCop version
The text was updated successfully, but these errors were encountered: