Skip to content

Commit

Permalink
[Fix #8132] Fix handling of names like _ and i with Naming/MethodName…
Browse files Browse the repository at this point in the history
… and EnforcedStyle: camelCase (#8140)
  • Loading branch information
avrusanov committed Jun 12, 2020
1 parent 44b5564 commit 018a042
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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][])
Expand Down Expand Up @@ -4586,3 +4587,4 @@
[@ric2b]: https://github.com/ric2b
[@burnettk]: https://github.com/burnettk
[@andrykonchin]: https://github.com/andrykonchin
[@avrusanov]: https://github.com/avrusanov
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/configurable_naming.rb
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/naming/variable_name_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 018a042

Please sign in to comment.