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

New `Lint/SelfAssignment` cop #8291

Closed
fatkodima opened this issue Jul 9, 2020 · 0 comments
Closed

New `Lint/SelfAssignment` cop #8291

fatkodima opened this issue Jul 9, 2020 · 0 comments

Comments

@fatkodima
Copy link
Contributor

@fatkodima fatkodima commented Jul 9, 2020

Self assignments have no effect, so probably those are a copy-parse error, missed self for properties or due to incomplete refactoring.

class User
  def fullname=(value)
    name, surname = value.split
    name = name # forgot to use `self`
    self.surname = surname
  end
end

x = x
[a, b] = [a, b]

There is already a Lint/UselessAssignment cop which checks for unused variables after assignment. That cop is a little difficult, as I can say, to extend with this and created with a little different purpose. So I'm proposing creating a new Lint/SelfAssignment cop to handle described use cases. Wdyt?

Inspired by https://eslint.org/docs/rules/no-self-assign and https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html#sa-self-assignment-of-field-sa-field-self-assignment and http://errorprone.info/bugpattern/SelfAssignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant
You can’t perform that action at this time.