Skip to content

Commit

Permalink
Merge pull request #12772 from Earlopain/fix-error-for-style-class-vars
Browse files Browse the repository at this point in the history
Fix an error for `Style/ClassVars` when calling `class_variable_set` without arguments
  • Loading branch information
koic committed Mar 10, 2024
2 parents 5ee786d + 94c17b8 commit 409c5a0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_style_class_vars.md
@@ -0,0 +1 @@
* [#12772](https://github.com/rubocop/rubocop/pull/12772): Fix an error for `Style/ClassVars` when calling `class_variable_set` without arguments. ([@earlopain][])
6 changes: 3 additions & 3 deletions lib/rubocop/cop/style/class_vars.rb
Expand Up @@ -54,9 +54,9 @@ def on_cvasgn(node)
end

def on_send(node)
add_offense(
node.first_argument, message: format(MSG, class_var: node.first_argument.source)
)
return unless (first_argument = node.first_argument)

add_offense(first_argument, message: format(MSG, class_var: first_argument.source))
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/rubocop/cop/style/class_vars_spec.rb
Expand Up @@ -28,4 +28,8 @@ class TestClass; end
it 'does not register an offense for class variable usage' do
expect_no_offenses('@@test.test(20)')
end

it 'registers no offense for class variable set without arguments' do
expect_no_offenses('class_variable_set')
end
end

0 comments on commit 409c5a0

Please sign in to comment.