Skip to content

Commit

Permalink
AllowedIdentifiers now also checks variable assignments (rubocop#9136)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilCoggins committed Dec 1, 2020
1 parent 18348ef commit 9a8777f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#9136](https://github.com/rubocop-hq/rubocop/pull/9136): Fix `AllowedIdentifiers` in `Naming/VariableNumber` to include variable assignments. ([@PhilCoggins][])
4 changes: 3 additions & 1 deletion lib/rubocop/cop/naming/variable_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class VariableNumber < Base
def on_arg(node)
@node = node
name, = *node
return if allowed_identifier?(name)

check_name(node, name, node.loc.name)
end
alias on_lvasgn on_arg
Expand Down Expand Up @@ -139,7 +141,7 @@ def message(style)
end

def allowed_identifier?(name)
allowed_identifiers.include?(name.to_s)
allowed_identifiers.include?(name.to_s.gsub('@', ''))
end

def allowed_identifiers
Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/cop/naming/variable_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,24 @@ def method1; end
}
end

it 'does not register an offense for a local variable name that is allowed' do
expect_no_offenses(<<~RUBY)
capture3 = :foo
RUBY
end

it 'does not register an offense for a instance variable name that is allowed' do
expect_no_offenses(<<~RUBY)
@capture3 = :foo
RUBY
end

it 'does not register an offense for a class variable name that is allowed' do
expect_no_offenses(<<~RUBY)
@@capture3 = :foo
RUBY
end

it 'does not register an offense for a method name that is allowed' do
expect_no_offenses(<<~RUBY)
def capture3
Expand Down

0 comments on commit 9a8777f

Please sign in to comment.