From 86156af939e41bcfd216a380f5e324808ee7a42a 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.md | 5 +++++ config/default.yml | 2 +- docs/modules/ROOT/pages/cops_performance.adoc | 10 +++++++--- lib/rubocop/cop/performance/casecmp.rb | 8 ++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbfd7b82d4..b05a1a725d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Changes + +* [#240](https://github.com/rubocop/rubocop-performance/issues/240): Retire `Performance/Casecmp` cop. ([@parkerfinch][]) + ## 1.11.2 (2021-05-05) ### Bug fixes @@ -271,3 +275,4 @@ [@dvandersluis]: https://github.com/dvandersluis [@ghiculescu]: https://github.com/ghiculescu [@mfbmina]: https://github.com/mfbmina +[@parkerfinch]: https://github.com/parkerfinch diff --git a/config/default.yml b/config/default.yml index e617662bd4..8eea0f89d6 100644 --- a/config/default.yml +++ b/config/default.yml @@ -52,7 +52,7 @@ Performance/Casecmp: Description: >- Use `casecmp` rather than `downcase ==`, `upcase ==`, `== downcase`, or `== upcase`.. Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringcasecmp-vs-stringdowncase---code' - Enabled: true + Enabled: false Safe: false VersionAdded: '0.36' diff --git a/docs/modules/ROOT/pages/cops_performance.adoc b/docs/modules/ROOT/pages/cops_performance.adoc index 2baa95b47a..1f1fc40d16 100644 --- a/docs/modules/ROOT/pages/cops_performance.adoc +++ b/docs/modules/ROOT/pages/cops_performance.adoc @@ -283,7 +283,7 @@ end |=== | Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged -| Enabled +| Disabled | No | Yes (Unsafe) | 0.36 @@ -292,8 +292,12 @@ end This cop identifies places where a case-insensitive string comparison can better be implemented using `casecmp`. -This cop is unsafe because `String#casecmp` and `String#casecmp?` behave -differently when using Non-ASCII characters. + +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. === Examples diff --git a/lib/rubocop/cop/performance/casecmp.rb b/lib/rubocop/cop/performance/casecmp.rb index c981757c79..1c4a1223fb 100644 --- a/lib/rubocop/cop/performance/casecmp.rb +++ b/lib/rubocop/cop/performance/casecmp.rb @@ -5,8 +5,12 @@ module Cop module Performance # This cop identifies places where a case-insensitive string comparison # can better be implemented using `casecmp`. - # This cop is unsafe because `String#casecmp` and `String#casecmp?` behave - # differently when using Non-ASCII characters. + # + # 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. # # @example # # bad