Skip to content

Commit

Permalink
[Fix rubocop#8726] Fix a false positive for Naming/VariableNumber
Browse files Browse the repository at this point in the history
Fixes rubocop#8726.

Fix a false positive for `Naming/VariableNumber`
when naming multibyte character variable name.
  • Loading branch information
koic committed Sep 16, 2020
1 parent 1345eff commit 0529b17
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
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ó'

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ó'

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

0 comments on commit 0529b17

Please sign in to comment.