Skip to content

Commit

Permalink
Merge pull request #11493 from koic/fix_an_error_for_lint_void
Browse files Browse the repository at this point in the history
[Fix #11492] Fix an error for `Lint/Void`
  • Loading branch information
koic committed Jan 24, 2023
2 parents 9a1f19a + 48f3d1f commit aa08c25
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
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

0 comments on commit aa08c25

Please sign in to comment.