Skip to content

Performance/MapCompact autocorrection leads to faulty syntax #247

Closed
@koppen

Description

@koppen

Expected behavior

Given the original code:

players.
  map(&:score).
  compact.
  max

I expect rubocop -A --only Performance/MapCompact to correct the code to

players.
  filter_map(&:score).
  max

Actual behavior

Instead, rubocop -A --only Performance/MapCompact corrects the code to

players.
  filter_map(&:score)
  max

which ultimately results in

undefined local variable or method `max' for main:Object (NameError)

RuboCop version

$ bundle exec rubocop -V
1.14.0 (using Parser 3.0.1.1, rubocop-ast 1.5.0, running on ruby 2.7.3 x86_64-darwin19)
  - rubocop-performance 1.11.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions