From 4dc1e5c5d6e0761d7d783ec543f6982e8a369ed0 Mon Sep 17 00:00:00 2001 From: Parker Finch Date: Wed, 5 May 2021 08:00:23 -0400 Subject: [PATCH] [Fix #240] Disable `Performance/Casecmp` cop 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. --- changelog/change_disalbe_performance_casecmp_by_default.md | 1 + config/default.yml | 3 ++- lib/rubocop/cop/performance/casecmp.rb | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelog/change_disalbe_performance_casecmp_by_default.md diff --git a/changelog/change_disalbe_performance_casecmp_by_default.md b/changelog/change_disalbe_performance_casecmp_by_default.md new file mode 100644 index 0000000000..4aacf83881 --- /dev/null +++ b/changelog/change_disalbe_performance_casecmp_by_default.md @@ -0,0 +1 @@ +* [#240](https://github.com/rubocop/rubocop-performance/issues/240): Disable `Performance/Casecmp` cop by default. ([@parkerfinch][]) diff --git a/config/default.yml b/config/default.yml index a508a39827..c9a434625b 100644 --- a/config/default.yml +++ b/config/default.yml @@ -55,9 +55,10 @@ Performance/Casecmp: Description: >- Use `casecmp` rather than `downcase ==`, `upcase ==`, `== downcase`, or `== upcase`.. Reference: 'https://github.com/fastruby/fast-ruby#stringcasecmp-vs--stringcasecmp-vs-stringdowncase---code' - Enabled: true + Enabled: false Safe: false VersionAdded: '0.36' + VersionChanged: '<>' Performance/ChainArrayAllocation: Description: >- diff --git a/lib/rubocop/cop/performance/casecmp.rb b/lib/rubocop/cop/performance/casecmp.rb index 29471c7d59..268934e78b 100644 --- a/lib/rubocop/cop/performance/casecmp.rb +++ b/lib/rubocop/cop/performance/casecmp.rb @@ -6,6 +6,12 @@ module Performance # Identifies places where a case-insensitive string comparison # can better be implemented using `casecmp`. # + # This cop is disabled by default because `String#casecmp` only works with + # ASCII characters. See https://github.com/rubocop/rubocop/issues/9753. + # + # If you are working only with ASCII characters, then this cop can be + # safely enabled. + # # @safety # This cop is unsafe because `String#casecmp` and `String#casecmp?` behave # differently when using Non-ASCII characters.