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
Style/ArrayCoercion does not work with Time objects #8334
Comments
https://ruby-doc.org/core-2.7.1/Kernel.html#method-i-Array describes Array
The So I assume for any object providing a |
Indeed. I think the equivalent of |
Well, I guess it's safe to say that this cop is unsafe. Still, most of the time it does improve the code a bit. |
I'm not sure I'd call it an improvement if it may change the code to something, that behaves differently than before. |
See also #8391 |
Fixes rubocop#8783, rubocop#8391, and rubocop#8334. This PR disables `Style/ArrayCoercion` cop by default. Because false positive will occur if the argument of `Array()` is not an array (e.g. Hash, Set), an array will be returned as an incompatibility result.
I think this should probably be closed now that #8792 is merged? |
Indeed 👍 |
The Style/ArrayCoercion cop introduced in #8295 has some unexpected auto-correct behavior if dealing with
Time
objects.Expected behavior
Style/ArrayCoercion auto-correct should not break code if dealing with
Time
objects.Actual behavior
Style/ArrayCoercion auto-correct breaks if the wrapped variable is a
Time
object.Steps to reproduce the problem
We have code like this to wrap an
Time
object calledinserted_at
in an ArrayThis was replaced by auto-correct with
This leads to an array with each part of the Time object as value
I don't know why this behavior happens, but it seems just calling Array on some object, my lead to unexpected breaks.
RuboCop version
The text was updated successfully, but these errors were encountered: