-
Notifications
You must be signed in to change notification settings - Fork 280
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
Variable assignment to self #1701
Comments
Ah yes, I was still going to find out what that code does if this is the first time It does look weird though so should definitely be caught by either Reek or RuboCop. |
should it detect any local variable + method with the same name? |
So in my mind foo = foo should be a smell regardless if the right hand foo is the same variable or a method. If the right hand foo is a variable its obviously wrong and if its a method then its confusing, particularly if used without the parentheses. If its about saving additional method calls then the left-hand foo should be named differently or it might be smarter to memoize that function call so subsequent calls are "for free". |
I just tested this, and this assigns the method result to the variable: foo = foo() while this does not and leaves foo foo = foo So, I agree the second form is bad and so does RuboCop. I'm not sure this is really a code smell though? Maybe this should be left to RuboCop instead? |
I was in the situation of replacing multiple method calls with variables and accidentally assigned the variable to itself without any modification. Would these be a useful smell to add?
Example:
foo = foo
The text was updated successfully, but these errors were encountered: