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

Performance Count Cop does not work #69

Closed
enthusiasmus opened this issue Jul 11, 2019 · 4 comments
Closed

Performance Count Cop does not work #69

enthusiasmus opened this issue Jul 11, 2019 · 4 comments

Comments

@enthusiasmus
Copy link


Expected behavior

I am expecting offenses for

        [1, 2, 3].select { |e| e > 2 }.size
        [1, 2, 3].reject { |e| e > 2 }.size
        [1, 2, 3].select { |e| e > 2 }.length
        [1, 2, 3].reject { |e| e > 2 }.length

as seen in https://github.com/rubocop-hq/rubocop-performance/blob/master/lib/rubocop/cop/performance/count.rb

Actual behavior

I don't receive offenses

Steps to reproduce the problem

file foobar.rb with

# frozen_string_literal: true

def foobar
  [1, 2, 3].select { |e| e > 2 }.size
  [1, 2, 3].reject { |e| e > 2 }.size
  [1, 2, 3].select { |e| e > 2 }.length
  [1, 2, 3].reject { |e| e > 2 }.length
end

executing rubocop performance via rubocop --require rubocop-performance foobar.rb

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:

$ [bundle exec] rubocop -V
0.72.0 (using Parser 2.6.3.0, running on ruby 2.6.3 x86_64-linux)

rubocop-performance version: 1.4.0
@koic
Copy link
Member

koic commented Jul 12, 2019

Please set SafeMode of Performance/Count cop to false in rubocop.yml.

Performance/Count:
  SafeMode: false

It is not working because SafeMode is true by default.
https://docs.rubocop.org/projects/performance/en/stable/cops_performance/#performancecount

Related resources

@rrosenblum
Copy link
Contributor

I came across this in the last day or two as well. Looking into it, I think the SafeMode on these cops has outlived its usefulness. SafeMode doesn't produce a single offense for either cop so it is the same as having it disabled by default. It is only documented inside of the default.yml file so user's don't know that the configuration exists. I think we would be better off disabling the cop by default, or changing it to be flagged as unsafe for auto-correction.

@enthusiasmus
Copy link
Author

Thanks for the hint and reply!

@koic
Copy link
Member

koic commented Nov 11, 2019

#72 has been released.

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

No branches or pull requests

3 participants