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

Cop idea: Add a cop similar to Style/RedundantFilterChain #1048

Closed
ydakuka opened this issue Jul 17, 2023 · 1 comment · Fixed by rubocop/rubocop#12126
Closed

Cop idea: Add a cop similar to Style/RedundantFilterChain #1048

ydakuka opened this issue Jul 17, 2023 · 1 comment · Fixed by rubocop/rubocop#12126

Comments

@ydakuka
Copy link

ydakuka commented Jul 17, 2023

Actual behavior

If I have the code:

# frozen_string_literal: true

module ApplicationHelper
  def my_method
    [1, 2, 3].select { |num| num == 3 }.any?
  end
end

I run rubocop and get offenses:

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop app/helpers/application_helper.rb
Inspecting 1 file
C

Offenses:

app/helpers/application_helper.rb:5:15: C: [Correctable] Style/RedundantFilterChain: Use any? instead of select.any?.
    [1, 2, 3].select { |num| num == 3 }.any?
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable

but if I have the following code:

# frozen_string_literal: true

module ApplicationHelper
  def my_method
    [1, 2, 3].select { |num| num == 3 }.present?
  end
end

I have no offences:

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop app/helpers/application_helper.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

Expected behavior

I expected to receive the following code:

# frozen_string_literal: true

module ApplicationHelper
  def my_method
    [1, 2, 3].any? { |num| num == 3 }
  end
end
koic added a commit to koic/rubocop that referenced this issue Aug 16, 2023
Resolves: rubocop/rubocop-rails#1048.

This PR makes `Style/RedundantFilterChain` aware of `select.present?`
when `AllCops/ActiveSupportExtensionsEnabled: true`.
bbatsov pushed a commit to rubocop/rubocop that referenced this issue Sep 28, 2023
Resolves: rubocop/rubocop-rails#1048.

This PR makes `Style/RedundantFilterChain` aware of `select.present?`
when `AllCops/ActiveSupportExtensionsEnabled: true`.
@ydakuka
Copy link
Author

ydakuka commented Oct 21, 2023

rubocop/rubocop#12301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant