Skip to content
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

[Fix #8726] Fix a false positive for Naming/VariableNumber #8727

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

* [#8720](https://github.com/rubocop-hq/rubocop/issues/8720): Fix an error for `Lint/IdentityComparison` when calling `object_id` method without receiver in LHS or RHS. ([@koic][])
* [#8710](https://github.com/rubocop-hq/rubocop/issues/8710): Fix a false positive for `Layout/RescueEnsureAlignment` when `Layout/BeginEndAlignment` cop is not enabled status. ([@koic][])
* [#8726](https://github.com/rubocop-hq/rubocop/issues/8726): Fix a false positive for `Naming/VariableNumber` when naming multibyte character variable name. ([@koic][])

### Changes

Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/mixin/configurable_numbering.rb
Expand Up @@ -8,9 +8,9 @@ module ConfigurableNumbering
include ConfigurableFormatting

FORMATS = {
snake_case: /(?:[a-z_]|_\d+)$/,
normalcase: /(?:_\D*|[A-Za-z]\d*)$/,
non_integer: /[A-Za-z_]$/
snake_case: /(?:[[[:lower:]]_]|_\d+)$/,
normalcase: /(?:_\D*|[[[:upper:]][[:lower:]]]\d*)$/,
non_integer: /[[[:upper:]][[:lower:]]_]$/
}.freeze
end
end
Expand Down
3 changes: 3 additions & 0 deletions spec/rubocop/cop/naming/variable_number_spec.rb
Expand Up @@ -54,6 +54,7 @@
it_behaves_like 'accepts', 'snake_case', '_foo'
it_behaves_like 'accepts', 'snake_case', '@foo'
it_behaves_like 'accepts', 'snake_case', '@__foo__'
it_behaves_like 'accepts', 'snake_case', 'emparejó'

it 'registers an offense for normal case numbering in method parameter' do
expect_offense(<<~RUBY)
Expand Down Expand Up @@ -98,6 +99,7 @@ def method(funnyArg1); end
it_behaves_like 'accepts', 'normalcase', '_foo'
it_behaves_like 'accepts', 'normalcase', '@foo'
it_behaves_like 'accepts', 'normalcase', '@__foo__'
it_behaves_like 'accepts', 'snake_case', 'emparejó'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have been normalcase instead of snake_case?


it 'registers an offense for snake case numbering in method parameter' do
expect_offense(<<~RUBY)
Expand Down Expand Up @@ -139,6 +141,7 @@ def method(funnyArg_1); end
it_behaves_like 'accepts', 'non_integer', '_'
it_behaves_like 'accepts', 'non_integer', '_foo'
it_behaves_like 'accepts', 'non_integer', '@__foo__'
it_behaves_like 'accepts', 'snake_case', 'emparejó'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here.


it 'registers an offense for snake case numbering in method parameter' do
expect_offense(<<~RUBY)
Expand Down