rubocop-performance icon indicating copy to clipboard operation
rubocop-performance copied to clipboard

Retire `Performance/Casecmp` cop

Open parkerfinch opened this issue 3 years ago • 2 comments

This follows up on the ideas generated in https://github.com/rubocop/rubocop-performance/issues/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 https://github.com/rubocop/rubocop/issues/9753, where I'm hoping we can create a Linting cop to suggest using casecmp?.

parkerfinch avatar May 05 '21 11:05 parkerfinch

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.

mlegner avatar Jan 19 '22 12:01 mlegner

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

Both lines above return the same offence message.

Checkout lines: https://github.com/rubocop/rubocop-performance/blob/219bf570999d291ef657de97792b493e43f42393/spec/rubocop/cop/performance/casecmp_spec.rb#L19 https://github.com/rubocop/rubocop-performance/blob/219bf570999d291ef657de97792b493e43f42393/spec/rubocop/cop/performance/casecmp_spec.rb#L41

Volosh1n avatar Mar 29 '22 17:03 Volosh1n