rubocop / rubocop-performance

An extension of RuboCop focused on code performance checks.
https://docs.rubocop.org/rubocop-performance
MIT License
682 stars 80 forks source link

Suggest: Disable String#casecmp cop for non-ASCII strings #441

Closed MaratKarimov21 closed 8 months ago

MaratKarimov21 commented 8 months ago

Hi everyone,

I just want to add my +1 to casecmp issues. My colleague, who is new to Ruby, got an offense for using the downcase method for comparison. He followed the instructions and fixed it as shown in the example, but the problem was that he was comparing against a non-ASCII string, which is why the code was not working properly. He didn't know the nuances of the casecmp method and said he spent an hour looking for the problem😅

I saw an open PR where this cop was proposed to be disabled, but it was decided to declare it unsafe.

My suggestion is to disable the check if the comparison involves a string containing non-ASCII characters, in order to avoid pushing people to misuse the casecmp method.

What do you think about this idea? I would be happy to participate and create a PR if you are OK with it.

koic commented 8 months ago

This is a dup with #240 and it will be fixed in #443. Thank you for the feedback.