Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Retire Performance/Casecmp cop #240

Closed
parkerfinch opened this issue May 5, 2021 · 2 comments
Closed

Retire Performance/Casecmp cop #240

parkerfinch opened this issue May 5, 2021 · 2 comments

Comments

@parkerfinch
Copy link
Contributor

This follows up on the ideas generated in #100.

It is confusing to have this cop enabled. Even when the autocorrection is marked as unsafe, the cop still directs people to use casecmp(...).zero?, which is incorrect in non-ascii use cases.

This issue pairs with rubocop/rubocop#9753, where I'm hoping we can create a Linting cop to suggest using casecmp?.

parkerfinch added a commit to parkerfinch/rubocop-performance that referenced this issue May 5, 2021
This cop suggests an incorrect fix when code involves non-ASCII
characters. Disabling it by default makes this risky behavior opt-in
rather than opt-out.
parkerfinch added a commit to parkerfinch/rubocop-performance that referenced this issue May 5, 2021
This cop suggests an incorrect fix when code involves non-ASCII
characters. Disabling it by default makes this risky behavior opt-in
rather than opt-out.
@mlegner
Copy link

mlegner commented Jan 19, 2022

There is another issue with the Performance/Casecmp cop: For str1.downcase == str2.downcase it suggests str1.casecmp(str2).zero?. But then Style/NumericPredicate jumps in to suggest str1.casecmp(str2) == 0 instead.

@Volosh1n
Copy link

Volosh1n commented Mar 29, 2022

Another issue with this cop:
str.#{selector} == ('string')
str.#{selector} != ('string')

Both lines above return the same offence message.

Checkout lines:

^^^^^{selector}^^^^^^^^^^^^^^ Use `str.casecmp('string').zero?` instead of `str.#{selector} == ('string')`.

^^^^^{selector}^^^^^^^^^^^^^^ Use `str.casecmp('string').zero?` instead of `str.#{selector} != ('string')`.

koic added a commit that referenced this issue Apr 1, 2022
patrickm53 pushed a commit to patrickm53/performance-develop-rubyonrails that referenced this issue Sep 23, 2022
richardstewart0213 added a commit to richardstewart0213/performance-build-Performance-optimization-analysis- that referenced this issue Nov 4, 2022
Cute0110 added a commit to Cute0110/Rubocop-Performance that referenced this issue Sep 28, 2023
SerhiiMisiura added a commit to SerhiiMisiura/Rubocop-Performance that referenced this issue Oct 5, 2023
@koic koic closed this as completed in 4dc1e5c Feb 17, 2024
koic added a commit that referenced this issue Feb 17, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants