From 0529b1744a903d2cfd9e4362f2e1cb8ea6fffd24 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 16 Sep 2020 15:36:06 +0900 Subject: [PATCH] [Fix #8726] Fix a false positive for `Naming/VariableNumber` Fixes #8726. Fix a false positive for `Naming/VariableNumber` when naming multibyte character variable name. --- CHANGELOG.md | 1 + lib/rubocop/cop/mixin/configurable_numbering.rb | 6 +++--- spec/rubocop/cop/naming/variable_number_spec.rb | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb8bed428db..6930b0a6878 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rubocop/cop/mixin/configurable_numbering.rb b/lib/rubocop/cop/mixin/configurable_numbering.rb index 88da10894d9..d8501443ce1 100644 --- a/lib/rubocop/cop/mixin/configurable_numbering.rb +++ b/lib/rubocop/cop/mixin/configurable_numbering.rb @@ -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 diff --git a/spec/rubocop/cop/naming/variable_number_spec.rb b/spec/rubocop/cop/naming/variable_number_spec.rb index f3d75429ff2..b7cc4dd20c5 100644 --- a/spec/rubocop/cop/naming/variable_number_spec.rb +++ b/spec/rubocop/cop/naming/variable_number_spec.rb @@ -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) @@ -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) @@ -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)