Skip to content

Commit

Permalink
[Fix rubocop#240] Disable Performance/Casecmp cop
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
parkerfinch committed May 5, 2021
1 parent 1db41d7 commit 2c2c218
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Changes

* [#240](https://github.com/rubocop/rubocop-performance/issues/240): Retire `Performance/Casecmp` cop

## 1.11.2 (2021-05-05)

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
10 changes: 7 additions & 3 deletions docs/modules/ROOT/pages/cops_performance.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ end
|===
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged

| Enabled
| Disabled
| No
| Yes (Unsafe)
| 0.36
Expand All @@ -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

Expand Down
8 changes: 6 additions & 2 deletions lib/rubocop/cop/performance/casecmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2c2c218

Please sign in to comment.