Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #11492] Fix an error for Lint/Void #11493

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_an_error_for_lint_void.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11492](https://github.com/rubocop/rubocop/issues/11492): Fix an error for `Lint/Void` when configuring `CheckForMethodsWithNoSideEffects: true`. ([@koic][])
2 changes: 2 additions & 0 deletions lib/rubocop/cop/lint/void.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def check_void_expression(node)
end

def check_nonmutating(node)
return unless node.respond_to?(:method_name)

method_name = node.method_name
return unless NONMUTATING_METHODS.include?(method_name)

Expand Down
7 changes: 7 additions & 0 deletions spec/rubocop/cop/lint/void_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ def foo
top(x)
RUBY
end

it 'does not register an offense assigning variable' do
expect_no_offenses(<<~RUBY)
foo = bar
baz
RUBY
end
end

context 'when not checking for methods with no side effects' do
Expand Down