You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Apologies if this already exists but I couldn't find anything by searching. Is there a way to report when the result of something like Array#sort or Hash#merge isn't captured?
Describe the solution you'd like
I'd like to see a cop that will detect when these types of methods are called but their return value isn't stored in a variable, passed as an argument, or used in some other way. In that case, I would like it if rubocop would suggest Array#sort! or Hash#merge! to do the operation in-place.
edit: It occurred to me after the fact that it's not always apparent that we're calling sort or merge on an Array or Hash and we wouldn't necessarily want to suggest sort! for other (possibly user-defined) classes where sort might have side effects. So I don't think this is easy to implement, at least not for a dynamically typed language like Ruby.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Apologies if this already exists but I couldn't find anything by searching. Is there a way to report when the result of something like
Array#sort
orHash#merge
isn't captured?Describe the solution you'd like
I'd like to see a cop that will detect when these types of methods are called but their return value isn't stored in a variable, passed as an argument, or used in some other way. In that case, I would like it if
rubocop
would suggestArray#sort!
orHash#merge!
to do the operation in-place.edit: It occurred to me after the fact that it's not always apparent that we're calling
sort
ormerge
on anArray
orHash
and we wouldn't necessarily want to suggestsort!
for other (possibly user-defined) classes wheresort
might have side effects. So I don't think this is easy to implement, at least not for a dynamically typed language like Ruby.The text was updated successfully, but these errors were encountered: