Skip to content

Commit

Permalink
[Fix #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 authored and koic committed Feb 15, 2024
1 parent dd698b2 commit 4dc1e5c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/change_disalbe_performance_casecmp_by_default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#240](https://github.com/rubocop/rubocop-performance/issues/240): Disable `Performance/Casecmp` cop by default. ([@parkerfinch][])
3 changes: 2 additions & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<<next>>'

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

0 comments on commit 4dc1e5c

Please sign in to comment.