class RuboCop::Cop::Style::RedundantArrayFlatten
x.join
# good
x.flatten(1).join
x.flatten.join
# bad
@example
false positives may occur.
Also, if the global variable ‘$,` is set to a value other than the default `nil`,
or the end result would be different.
be an `Array`, so it’s possible it won’t respond to ‘join` method,
Cop is unsafe because the receiver of `flatten` method might not
@safety
beforehand is redundant.
`Array#join` joins nested arrays recursively, so flattening an array
Checks for redundant calls of `Array#flatten`.
def on_send(node)
def on_send(node) return unless flatten_join?(node.parent) range = node.loc.dot.begin.join(node.source_range.end) add_offense(range) do |corrector| corrector.remove(range) end end