From 018a04280a60660be2e09b91a4e2284f45a2f802 Mon Sep 17 00:00:00 2001 From: avrusanov <49242440+avrusanov@users.noreply.github.com> Date: Fri, 12 Jun 2020 13:03:39 +0500 Subject: [PATCH] [Fix #8132] Fix handling of names like _ and i with Naming/MethodName and EnforcedStyle: camelCase (#8140) --- CHANGELOG.md | 2 ++ lib/rubocop/cop/mixin/configurable_naming.rb | 2 +- spec/rubocop/cop/naming/variable_name_spec.rb | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bc193cac1b..166f0e55c92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Bug fixes +* [#8132](https://github.com/rubocop-hq/rubocop/issues/8132): Fix the problem with `Naming/MethodName: EnforcedStyle: camelCase` and `_` or `i` variables. ([@avrusanov][]) * [#8115](https://github.com/rubocop-hq/rubocop/issues/8115): Fix false negative for `Lint::FormatParameterMismatch` when argument contains formatting. ([@andrykonchin][]) * [#8131](https://github.com/rubocop-hq/rubocop/pull/8131): Fix false positive for `Style/RedundantRegexpEscape` with escaped delimiters. ([@owst][]) * [#8124](https://github.com/rubocop-hq/rubocop/issues/8124): Fix a false positive for `Lint/FormatParameterMismatch` when using named parameters with escaped `%`. ([@koic][]) @@ -4586,3 +4587,4 @@ [@ric2b]: https://github.com/ric2b [@burnettk]: https://github.com/burnettk [@andrykonchin]: https://github.com/andrykonchin +[@avrusanov]: https://github.com/avrusanov diff --git a/lib/rubocop/cop/mixin/configurable_naming.rb b/lib/rubocop/cop/mixin/configurable_naming.rb index e9829a077a8..49734795aa8 100644 --- a/lib/rubocop/cop/mixin/configurable_naming.rb +++ b/lib/rubocop/cop/mixin/configurable_naming.rb @@ -9,7 +9,7 @@ module ConfigurableNaming FORMATS = { snake_case: /^@{0,2}[\da-z_]+[!?=]?$/, - camelCase: /^@{0,2}_?[a-z][\da-zA-Z]+[!?=]?$/ + camelCase: /^@{0,2}(?:_|_?[a-z][\da-zA-Z]*)[!?=]?$/ }.freeze end end diff --git a/spec/rubocop/cop/naming/variable_name_spec.rb b/spec/rubocop/cop/naming/variable_name_spec.rb index f7f4798fed8..5513771c36d 100644 --- a/spec/rubocop/cop/naming/variable_name_spec.rb +++ b/spec/rubocop/cop/naming/variable_name_spec.rb @@ -17,6 +17,14 @@ it 'accepts assignment with indexing of self' do expect_no_offenses('self[:a] = b') end + + it 'accepts local variables marked as unused' do + expect_no_offenses('_ = 1') + end + + it 'accepts one symbol size local variables' do + expect_no_offenses('i = 1') + end end context 'when configured for snake_case' do