Skip to content

Style/RedundantArrayFlatten can be unsafe when the Array contains empty Arrays and join uses a separator #14249

@JasonBarnabe

Description

@JasonBarnabe
> ['a', [], 'b'].flatten.join("\n")
=> "a\nb"

got corrected to:

> ['a', [], 'b'].join("\n")
=> "a\n\nb"

which is a different result. Should be mentioned in the docs, at least.

1.76.0 (using Parser 3.3.8.0, Prism 1.4.0, rubocop-ast 1.45.0, analyzing as Ruby 3.4, running on ruby 3.4.2) [x86_64-linux]
  - rubocop-rails 2.32.0
  - rubocop-minitest 0.38.1
  - rubocop-performance 1.25.0
  - rubocop-capybara 2.22.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions