Skip to content

Commit

Permalink
[Fix #2758] Fix camel case variables not allowing underscore prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcguinn committed Feb 3, 2016
1 parent a31007a commit 0e1f2ed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -42,6 +42,7 @@
* [#2721](https://github.com/bbatsov/rubocop/issues/2721): Do not register an offense for constants wrapped in parentheses passed to `rescue` in `Style/RedundantParentheses`. ([@rrosenblum][])
* [#2742](https://github.com/bbatsov/rubocop/issues/2742): Fix `Style/TrailingCommaInArguments` & `Style/TrailingCommaInLiteral` for inline single element arrays. ([@annih][])
* [#2768](https://github.com/bbatsov/rubocop/issues/2768): Allow parentheses after keyword `not` in `Style/MethodCallParentheses`. ([@lumeet][])
* [#2758](https://github.com/bbatsov/rubocop/issues/2758): Allow leading underscores in camel case variable names.([@mmcguinn][])

### Changes

Expand Down Expand Up @@ -1934,3 +1935,4 @@
[@seikichi]: https://github.com/seikichi
[@madwort]: https://github.com/madwort
[@annih]: https://github.com/annih
[@mmcguinn]: https://github.com/mmcguinn
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/configurable_naming.rb
Expand Up @@ -9,7 +9,7 @@ module ConfigurableNaming
include ConfigurableEnforcedStyle

SNAKE_CASE = /^@{0,2}[\da-z_]+[!?=]?$/
CAMEL_CASE = /^@{0,2}[a-z][\da-zA-Z]+[!?=]?$/
CAMEL_CASE = /^@{0,2}_?[a-z][\da-zA-Z]+[!?=]?$/

def check_name(node, name, name_range)
return if operator?(name)
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/style/variable_name_spec.rb
Expand Up @@ -64,6 +64,12 @@
expect(cop.highlights).to eq(['funnyArg'])
end

it 'registers an offense for camel case local variables marked as unused' do
inspect_source(cop, '_myLocal = 1')
expect(cop.offenses.size).to eq(1)
expect(cop.highlights).to eq(['_myLocal'])
end

include_examples 'always accepted'
end

Expand Down Expand Up @@ -106,6 +112,11 @@
expect(cop.highlights).to eq(['funny_arg'])
end

it 'accepts camel case local variables marked as unused' do
inspect_source(cop, '_myLocal = 1')
expect(cop.offenses).to be_empty
end

include_examples 'always accepted'
end

Expand Down

0 comments on commit 0e1f2ed

Please sign in to comment.