-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new Lint/NumberedParameterAssignment
cop
#9326
Add new Lint/NumberedParameterAssignment
cop
#9326
Conversation
I like the cop, but I find the name a bit confusing, as the assignment is just the only place where we can check about the naming reliably, but orthogonal to the naming itself. I'm wondering if this shouldn't be incorporated in |
@rubocop-hq/rubocop-core If anyone has suggestions how to name this better or whether to integrate it into |
@koic You wrote that you put the new cop in |
52d8b74
to
f8468fe
Compare
Naming/NumberedParameterAssignment
copLint/NumberedParameterAssignment
cop
Yeah, what I originally tried to focus on was that assigning to numbered parameters ( So I reconsidered |
This cop checks for uses of numbered parameter assignment. It emulates the following warning in Ruby 2.7: ```console % ruby -ve '_1 = :value' ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19] -e:1: warning: `_1' is reserved for numbered parameter; consider another name ``` Assiging to numbered parameter (from `_1` to `_9`) cause an error in Ruby 3.0. ```console % ruby -ve '_1 = :value' ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19] -e:1: _1 is reserved for numbered parameter ``` NOTE: The parametered parameters are from `_1` to `_9`. This cop checks `_10` and above as well to prevent confusion. ```ruby # bad _1 = :value # good non_numbered_parameter = :value ``` This cop checks numbered (block) parameter other than `_1` to `_9` (e.g.: `_0`, `_10`).
f8468fe
to
d47750b
Compare
Let's merge the PR after the next bugfix release. I plan to do it Monday morning. |
* Update rubocop from 1.12.1 to [1.13.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.13.0) * Update rubocop-performance from 1.9.2 to [1.11.1](https://github.com/rubocop-hq/rubocop-performance/releases/tag/v1.11.1) * Enabled the following rules: * [`Performance/RedundantSplitRegexpArgument`](rubocop/rubocop-performance#190) * [`Style/IfWithBooleanLiteralBranches`](rubocop/rubocop#9396) * [`Lint/TripleQuotes`](rubocop/rubocop#9402) * [`Lint/SymbolConversion`](rubocop/rubocop#9362) * [`Lint/OrAssignmentToConstant`](rubocop/rubocop#9363) * [`Lint/NumberedParameterAssignment`](rubocop/rubocop#9326) * [`Style/HashConversion`](rubocop/rubocop#9478) * [`Gemspec/DateAssignment`](rubocop/rubocop#9496) * [`Style/StringChars`](rubocop/rubocop#9615)
This cop checks for uses of numbered parameter assignment.
It emulates the following warning in Ruby 2.7:
Assiging to numbered parameter (from
_1
to_9
) cause an error in Ruby 3.0.NOTE: The parametered parameters are from
_1
to_9
. This cop checks_10
andabove as well to prevent confusion.
This cop checks numbered (block) parameter other than
_1
to_9
(e.g.:_0
,_10
),it is placed in the
Naming
department instead ofLint
department.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.