Closed
Description
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
Activity