-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Lint/UnneededSplatExpansion: wrong unnecessary splat expansion. #3662
Comments
I tried putting together a bugfix, but came across this:
This^ should be |
@tejasbubane, I am not seeing the same issue with the code parsing that you are with the given example. What are versions of parser and ruby that you are using? Mine are [9] pry(#<RuboCop::Cop::Lint::UnneededSplatExpansion>)> node.source
=> "*[1, 2, 3]"
[10] pry(#<RuboCop::Cop::Lint::UnneededSplatExpansion>)> node
=> s(:splat,
s(:array,
s(:int, 1),
s(:int, 2),
s(:int, 3)))
[11] pry(#<RuboCop::Cop::Lint::UnneededSplatExpansion>)> node.parent.source
=> "[*[1, 2, 3]]"
[12] pry(#<RuboCop::Cop::Lint::UnneededSplatExpansion>)> node.parent
=> s(:array,
s(:splat,
s(:array,
s(:int, 1),
s(:int, 2),
s(:int, 3)))) I was able to reproduce what you saw with the [1] pry(#<RuboCop::Cop::Lint::UnneededSplatExpansion>)> node.source
=> "*[1, 2, 3]"
[2] pry(#<RuboCop::Cop::Lint::UnneededSplatExpansion>)> node
=> s(:splat,
s(:array,
s(:int, 1),
s(:int, 2),
s(:int, 3)))
[3] pry(#<RuboCop::Cop::Lint::UnneededSplatExpansion>)> node.parent.source
=> "*[1, 2, 3]"
[4] pry(#<RuboCop::Cop::Lint::UnneededSplatExpansion>)> node.parent
=> s(:array,
s(:splat,
s(:array,
s(:int, 1),
s(:int, 2),
s(:int, 3))))
[5] pry(#<RuboCop::Cop::Lint::UnneededSplatExpansion>)> node.parent.parent.source
=> "foo = *[1, 2, 3]"
[6] pry(#<RuboCop::Cop::Lint::UnneededSplatExpansion>)> node.parent.parent
=> s(:lvasgn, :foo,
s(:array,
s(:splat,
s(:array,
s(:int, 1),
s(:int, 2),
s(:int, 3))))) @victorfeijo, this doesn't look like it will be difficult to fix. We just need to change the correction if we are in an array. |
…ed in another array
Expected behaviour
Hello! I'm having a issue with Rubocop warning this code:
[*'A'..'H', *%w(J K M N), *'P'..'Z', *'0'..'9']
Unnecessary splat expansion in*%w(J K M N)
Which gives me something like
['A', 'B', 'C', 'D' 'E' .. 'J', 'K', 'M', 'N', 'P' .. '0', .. '9']
.Actual behaviour
When i use
rubocop -a filename
, the cop just removes the*
from*%w(J K M N)
and the returned data appears to be something different like:['A', 'B', 'C', ['J', K', 'M', 'N'], 'P' ... '0']
It creates a new array inside. I'm trying
# disable
instead but would be good if i could keep both running, rubocop and*%w(J K M N)
RuboCop version
The text was updated successfully, but these errors were encountered: