Skip to content

RuboCop::Cop::Performance::Casecmp broke my code #101

Closed
@hqm42

Description

@hqm42

a.casecmp(b).zero? is not an universal replacement for a.downcase == b.downcase

casecmp only supports characters A-Za-z. downcase supports special characters as well "ÄÖÜ".downcase == "äöü"


Expected behavior

Rubocop does not change the semantics of my program.

Actual behavior

Rubocop breaks my code.

Steps to reproduce the problem

foo.rb

# frozen_string_literal: true

if 'Grün'.downcase == 'GRÜN'.downcase
  puts 'this should be the same'
else
  puts 'rubocop broke my code'
end

rubocop -a foo.rb

foo.rb

# frozen_string_literal: true

if 'Grün'.casecmp('GRÜN').zero?
  puts 'this should be the same'
else
  puts 'rubocop broke my code'
end

RuboCop version

> bundle exec rubocop -V
0.80.0 (using Parser 2.7.0.3, running on ruby 2.5.3 x86_64-linux)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions