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 #8422] Fix an error for Lint/SelfAssignment #8428

Merged
merged 1 commit into from Jul 31, 2020
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.md
Expand Up @@ -29,6 +29,7 @@
* [#8391](https://github.com/rubocop-hq/rubocop/issues/8391): Mark `Style/ArrayCoercion` as not safe. ([@marcandre][])
* [#8406](https://github.com/rubocop-hq/rubocop/issues/8406): Improve `Style/AccessorGrouping`'s auto-correction to remove redundant blank lines. ([@koic][])
* [#8330](https://github.com/rubocop-hq/rubocop/issues/8330): Fix a false positive for `Style/MissingRespondToMissing` when defined method with inline access modifier. ([@koic][])
* [#8422](https://github.com/rubocop-hq/rubocop/issues/8422): Fix an error for `Lint/SelfAssignment` when using or-assignment for constant. ([@koic][])

### Changes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/self_assignment.rb
Expand Up @@ -40,7 +40,7 @@ def on_lvasgn(node)

def on_casgn(node)
lhs_scope, lhs_name, rhs = *node
return unless rhs.const_type?
return unless rhs&.const_type?

rhs_scope, rhs_name = *rhs
add_offense(node) if lhs_scope == rhs_scope && lhs_name == rhs_name
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/lint/self_assignment_spec.rb
Expand Up @@ -68,6 +68,12 @@
RUBY
end

it 'does not register an offense when using constant var or-assignment for constant from another scope' do
expect_no_offenses(<<~RUBY)
Foo ||= ::Foo
RUBY
end

it 'registers an offense when using multiple var self-assignment' do
expect_offense(<<~RUBY)
foo, bar = foo, bar
Expand Down