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

Broken reverse_each autocorrect #230

Closed
ignat-z opened this issue Dec 18, 2020 · 2 comments · Fixed by rubocop/rubocop-performance#201 or #234
Closed

Broken reverse_each autocorrect #230

ignat-z opened this issue Dec 18, 2020 · 2 comments · Fixed by rubocop/rubocop-performance#201 or #234
Labels
rubocop bug 🚨 An apparent bug in RuboCop

Comments

@ignat-z
Copy link

ignat-z commented Dec 18, 2020

It seems like standard produces incorrect code for multiline reverse.each.
Cop: Performance/ReverseEach: Use 'reverse_each' instead of 'reverse.each'.

Minimal source to reproduce:

[1, 2, 3]
  .reverse
  .each do |idx|
    puts idx
  end
# standardrb examplex.rb --fix
[1, 2, 3]
  .reverse
_each do |idx|
  puts idx
end
# rubocop -A examplex.rb
# frozen_string_literal: true

[1, 2, 3]
  .reverse
  .each do |idx|
    puts idx
  end
        Ruby version: 2.7.1
     RuboCop version: 1.4.2
    Standard version: 0.10.2
Standard config file: [No file found]
@ignat-z ignat-z changed the title Broken reverse_each fix Broken reverse_each autocorrect Dec 18, 2020
koic added a commit to koic/rubocop-performance that referenced this issue Dec 18, 2020
Fixes standardrb/standard#230.

This PR fixes the following incorrect auto-correct for `Performance/ReverseEach`
when using multi-line `reverse.each` with leading dot.

```ruby
% cat example.rb
[1, 2, 3]
  .reverse
  .each do |idx|
    puts idx
  end
```

## Before

```console
% bundle exec rubocop -a --only Performance/ReverseEach
% cat example.rb
[1, 2, 3]
  .reverse
  _each do |idx|
    puts idx
  end
```

## After

```console
% bundle exec rubocop -a --only Performance/ReverseEach
% cat example.rb
[1, 2, 3]
  .reverse_each do |idx|
    puts idx
  end
```
@koic
Copy link
Contributor

koic commented Dec 18, 2020

This is a bug of RuboCop Performance. It will be fixed by rubocop/rubocop-performance#201. Thank you for your feedback.

@jmkoni jmkoni added the rubocop bug 🚨 An apparent bug in RuboCop label Dec 18, 2020
@koic
Copy link
Contributor

koic commented Jan 1, 2021

This issue has been resolved by RuboCop Performance 1.9.2. Thank you 🌅

patrickm53 pushed a commit to patrickm53/performance-develop-rubyonrails that referenced this issue Sep 23, 2022
Fixes standardrb/standard#230.

This PR fixes the following incorrect auto-correct for `Performance/ReverseEach`
when using multi-line `reverse.each` with leading dot.

```ruby
% cat example.rb
[1, 2, 3]
  .reverse
  .each do |idx|
    puts idx
  end
```

## Before

```console
% bundle exec rubocop -a --only Performance/ReverseEach
% cat example.rb
[1, 2, 3]
  .reverse
  _each do |idx|
    puts idx
  end
```

## After

```console
% bundle exec rubocop -a --only Performance/ReverseEach
% cat example.rb
[1, 2, 3]
  .reverse_each do |idx|
    puts idx
  end
```
richardstewart0213 added a commit to richardstewart0213/performance-build-Performance-optimization-analysis- that referenced this issue Nov 4, 2022
Fixes standardrb/standard#230.

This PR fixes the following incorrect auto-correct for `Performance/ReverseEach`
when using multi-line `reverse.each` with leading dot.

```ruby
% cat example.rb
[1, 2, 3]
  .reverse
  .each do |idx|
    puts idx
  end
```

## Before

```console
% bundle exec rubocop -a --only Performance/ReverseEach
% cat example.rb
[1, 2, 3]
  .reverse
  _each do |idx|
    puts idx
  end
```

## After

```console
% bundle exec rubocop -a --only Performance/ReverseEach
% cat example.rb
[1, 2, 3]
  .reverse_each do |idx|
    puts idx
  end
```
Cute0110 added a commit to Cute0110/Rubocop-Performance that referenced this issue Sep 28, 2023
Fixes standardrb/standard#230.

This PR fixes the following incorrect auto-correct for `Performance/ReverseEach`
when using multi-line `reverse.each` with leading dot.

```ruby
% cat example.rb
[1, 2, 3]
  .reverse
  .each do |idx|
    puts idx
  end
```

## Before

```console
% bundle exec rubocop -a --only Performance/ReverseEach
% cat example.rb
[1, 2, 3]
  .reverse
  _each do |idx|
    puts idx
  end
```

## After

```console
% bundle exec rubocop -a --only Performance/ReverseEach
% cat example.rb
[1, 2, 3]
  .reverse_each do |idx|
    puts idx
  end
```
SerhiiMisiura added a commit to SerhiiMisiura/Rubocop-Performance that referenced this issue Oct 5, 2023
Fixes standardrb/standard#230.

This PR fixes the following incorrect auto-correct for `Performance/ReverseEach`
when using multi-line `reverse.each` with leading dot.

```ruby
% cat example.rb
[1, 2, 3]
  .reverse
  .each do |idx|
    puts idx
  end
```

## Before

```console
% bundle exec rubocop -a --only Performance/ReverseEach
% cat example.rb
[1, 2, 3]
  .reverse
  _each do |idx|
    puts idx
  end
```

## After

```console
% bundle exec rubocop -a --only Performance/ReverseEach
% cat example.rb
[1, 2, 3]
  .reverse_each do |idx|
    puts idx
  end
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rubocop bug 🚨 An apparent bug in RuboCop
Projects
None yet
3 participants