Skip to content
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

Invalid autocorrection (breaks existing code) for Performance/MapCompact #257

Closed
Drowze opened this issue Aug 12, 2021 · 0 comments · Fixed by #258
Closed

Invalid autocorrection (breaks existing code) for Performance/MapCompact #257

Drowze opened this issue Aug 12, 2021 · 0 comments · Fixed by #258
Labels
bug Something isn't working

Comments

@Drowze
Copy link

Drowze commented Aug 12, 2021

Expected behavior

I expect rubocop no to break existing code.

Actual behavior

Rubocop breaks existing code.

Steps to reproduce the problem

Given .rubocop.yml:

require: rubocop-performance

AllCops:
  NewCops: enable
  TargetRubyVersion: 2.7

And given test.rb:

# frozen_string_literal: true

repository.create!(
  Array(params[:events]).map do |params|
    data = event_data(params)
    {
      **data
    }
  end.compact
)

When I run rubocop -A test.rb, it outputs:

For /Users/Drowze/ruby/rubocop_bug7: configuration from /Users/Drowze/ruby/rubocop_bug7/.rubocop.yml
configuration from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-performance-1.11.4/config/default.yml
configuration from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-performance-1.11.4/config/default.yml
Default configuration from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.19.0/config/default.yml
Inspecting 1 file
Scanning /Users/Drowze/ruby/rubocop_bug7/test.rb
Loading cache from /Users/Drowze/.cache/rubocop_cache/f0f413cc0be14af33a3caa9ba80935194e168704/a787bfe2a02a843b5735436d51733fbf12391c24/edcf63b6565a57f3ef1a79c9b60fc40c9ef9870a
E

Offenses:

test.rb:4:26: C: [Corrected] Performance/MapCompact: Use filter_map instead.
  Array(params[:events]).map do |params| ...
                         ^^^^^^^^^^^^^^^
test.rb:9:1: E: Lint/Syntax: unexpected token tRPAREN
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)
)
^

1 file inspected, 2 offenses detected, 1 offense corrected
Finished in 0.39207099995110184 seconds

And leaves the file as (notice there's no end for the filter_map block)

# frozen_string_literal: true

repository.create!(
  Array(params[:events]).filter_map do |params|
    data = event_data(params)
    {
      **data
    }
)

RuboCop version

$ rubocop -V
1.19.0 (using Parser 3.0.2.0, rubocop-ast 1.9.1, running on ruby 2.7.3 x86_64-darwin20)
  - rubocop-performance 1.11.4
@koic koic added the bug Something isn't working label Aug 12, 2021
koic added a commit to koic/rubocop-performance that referenced this issue Aug 13, 2021
…ompact`

This PR fixes an incorrect auto-correct for `Performance/MapCompact` when
using multi-line `collection.map { |item| }.compact` as a method argument.
koic added a commit to koic/rubocop-performance that referenced this issue Aug 13, 2021
…ompact`

This PR fixes an incorrect auto-correct for `Performance/MapCompact` when
using multi-line `collection.map { ... }.compact` as a method argument.
koic added a commit to koic/rubocop-performance that referenced this issue Aug 13, 2021
…ompact`

Fixes rubocop#257.

This PR fixes an incorrect auto-correct for `Performance/MapCompact` when
using multi-line `collection.map { ... }.compact` as a method argument.
koic added a commit to koic/rubocop-performance that referenced this issue Aug 14, 2021
…ompact`

Fixes rubocop#257.

This PR fixes an incorrect auto-correct for `Performance/MapCompact` when
using multi-line `collection.map { ... }.compact` as a method argument.
@koic koic closed this as completed in #258 Aug 15, 2021
koic added a commit that referenced this issue Aug 15, 2021
…rformance_map_compact_cop

[Fix #257] Fix an incorrect auto-correct for `Performance/MapCompact`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants