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

Extend Style/SelfAssignment beyond variables #12410

Closed
vlad-pisanov opened this issue Nov 24, 2023 · 2 comments
Closed

Extend Style/SelfAssignment beyond variables #12410

vlad-pisanov opened this issue Nov 24, 2023 · 2 comments

Comments

@vlad-pisanov
Copy link

Is there a reason why Style/SelfAssignment only works with variables, as opposed to general expressions? I.e. could we lint for something like:

# bad
hash['foo'] = hash['foo'] + 42
user.name = user.name + " Jr."

# good
hash['foo'] += 42
user.name += " Jr."
@ydakuka
Copy link

ydakuka commented Nov 24, 2023

And (see ops):

# bad

x = x % 2
x = x ^ 2
x = x << 2
x = x >> 2
# good

x %= 2
x ^= 2
x <<= 2
x >>= 2

koic added a commit to koic/rubocop that referenced this issue Nov 29, 2023
Follow up rubocop#12410 (comment).

This PR makes `Style/SelfAssignment` aware of `%`, `^`, `<<`, and `>>` operators.
@koic
Copy link
Member

koic commented Nov 29, 2023

The main issue was resolved by #12415, and the derivative will be resolved by #12421.

@koic koic closed this as completed Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants